Module: StateShifter::Definition::ClassMethods
- Defined in:
- lib/state_shifter/definition/class_methods.rb
Instance Attribute Summary collapse
-
#_include_state_scopes ⇒ Object
Returns the value of attribute _include_state_scopes.
-
#persist_attr_name ⇒ Object
Returns the value of attribute persist_attr_name.
-
#state_machine_definition ⇒ Object
Returns the value of attribute state_machine_definition.
Instance Method Summary collapse
- #_load_tag(tag, states) ⇒ Object
- #persist_attribute(attr_name) ⇒ Object
- #state_machine(&definition) ⇒ Object
Instance Attribute Details
#_include_state_scopes ⇒ Object
Returns the value of attribute _include_state_scopes.
5 6 7 |
# File 'lib/state_shifter/definition/class_methods.rb', line 5 def _include_state_scopes @_include_state_scopes end |
#persist_attr_name ⇒ Object
Returns the value of attribute persist_attr_name.
5 6 7 |
# File 'lib/state_shifter/definition/class_methods.rb', line 5 def persist_attr_name @persist_attr_name end |
#state_machine_definition ⇒ Object
Returns the value of attribute state_machine_definition.
5 6 7 |
# File 'lib/state_shifter/definition/class_methods.rb', line 5 def state_machine_definition @state_machine_definition end |
Instance Method Details
#_load_tag(tag, states) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/state_shifter/definition/class_methods.rb', line 89 def _load_tag(tag, states) module_eval do define_singleton_method "#{tag}_states" do states end define_method "#{tag}?" do states.map(&:to_s).include? current_state.to_s end end end |
#persist_attribute(attr_name) ⇒ Object
7 8 9 10 |
# File 'lib/state_shifter/definition/class_methods.rb', line 7 def persist_attribute attr_name raise PersistenceAttributeAlreadyDefined if @persist_attr_name @persist_attr_name = attr_name.to_sym end |
#state_machine(&definition) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/state_shifter/definition/class_methods.rb', line 12 def state_machine &definition @persist_attr_name ||= :current_state @state_machine_definition = Contents.new(&definition) @state_machine_definition.states.each { |name, definition| _load_state(name, definition) } @state_machine_definition..each { |tag, states| _load_tag(tag, states) } ActiveRecordIntegrationMethods.include_state_scopes(self) if _include_state_scopes end |