Module: ActiveState::Model::ClassMethods

Defined in:
lib/active_state/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#initial_stateObject

Returns the value of attribute initial_state.



4
5
6
# File 'lib/active_state/model.rb', line 4

def initial_state
  @initial_state
end

Instance Method Details

#scope_for_state(*states, **named) ⇒ Object

Creates scopes for the given states in this form: scope :my_state, -> { where state_name: MyState.name }

Also accepts pairs of scope_name: StateClass pairs: scope :scope_name, -> { where state_name: StateClass.name }



12
13
14
15
16
17
18
19
# File 'lib/active_state/model.rb', line 12

def scope_for_state(*states, **named)
  states.each do |state|
    named[state.name.demodulize.underscore] = state
  end
  named.each do |k, v|
    scope k, -> { where state_name: v.name }
  end
end