8000 AASM defines constants for each state name by jherdman · Pull Request #60 · aasm/aasm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

AASM defines constants for each state name #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2013

Conversation

jherdman
Copy link
Contributor

So, I found I was hard coding state names in situations such as tests, or custom scopes. Hard coding such things is a bad thing, so I wrote this pull request to auto-define constants for each defined state.

Example:

class Foo
  include AASM

  aasm do
    state :initialized
    state :calculated
    state :finalized
  end
end

> Foo::STATE_INITIALIZED
#=> :initialized
> Foo::STATE_CALCULATED
#=> :calculated

Example:

  class Foo
    include AASM

    aasm do
      state :initialized
      state :calculated
      state :finalized
    end
  end

  > Foo::STATE_INITIALIZED
  => :initialized
  > Foo::STATE_CALCULATED
  => :calculated

You may find this useful in custom scopes when using ActiveRecord, or
when testing your classes.
alto added a commit that referenced this pull request Mar 20, 2013
AASM defines constants for each state name
@alto alto merged commit 636a25f into aasm:master Mar 20, 2013
@alto
Copy link
Member
alto commented Mar 20, 2013

Nice work! Thanks a lot! :)

@jherdman jherdman deleted the auto-define-state-constants branch March 20, 2013 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0