Class: RailsStateMachine::StateMachine
- Inherits:
-
Object
- Object
- RailsStateMachine::StateMachine
- Defined in:
- lib/rails_state_machine/state_machine.rb
Instance Method Summary collapse
- #configure(&block) ⇒ Object
- #event_names ⇒ Object
- #events ⇒ Object
- #find_event(name) ⇒ Object
- #has_state?(name) ⇒ Boolean
-
#initialize(model) ⇒ StateMachine
constructor
A new instance of StateMachine.
- #state_names ⇒ Object
- #states ⇒ Object
Constructor Details
#initialize(model) ⇒ StateMachine
Returns a new instance of StateMachine.
3 4 5 6 7 8 9 10 11 |
# File 'lib/rails_state_machine/state_machine.rb', line 3 def initialize(model) @model = model model_constant('StateMachineMethods', Module.new) @model.include(@model::StateMachineMethods) @states_by_name = {} @events_by_name = {} end |
Instance Method Details
#configure(&block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rails_state_machine/state_machine.rb', line 13 def configure(&block) instance_eval(&block) define_state_methods define_state_constants register_initial_state define_event_methods register_callbacks register_validations register_state_machine define_model_methods end |
#event_names ⇒ Object
41 42 43 |
# File 'lib/rails_state_machine/state_machine.rb', line 41 def event_names @events_by_name.keys end |
#events ⇒ Object
37 38 39 |
# File 'lib/rails_state_machine/state_machine.rb', line 37 def events @events_by_name.values end |
#find_event(name) ⇒ Object
45 46 47 |
# File 'lib/rails_state_machine/state_machine.rb', line 45 def find_event(name) @events_by_name.fetch(name.to_sym) end |
#has_state?(name) ⇒ Boolean
49 50 51 |
# File 'lib/rails_state_machine/state_machine.rb', line 49 def has_state?(name) @states_by_name.key?(name.to_sym) end |
#state_names ⇒ Object
33 34 35 |
# File 'lib/rails_state_machine/state_machine.rb', line 33 def state_names @states_by_name.keys end |
#states ⇒ Object
29 30 31 |
# File 'lib/rails_state_machine/state_machine.rb', line 29 def states @states_by_name.values end |