Module: StateMachina::Integration::ClassMethods
- Defined in:
- lib/state_machina/integration.rb
Instance Method Summary collapse
-
#define_machine(machine_name = 'default', column_name: :state, metadata: {}) {|StateMachina::Registry.register_machine(machine)| ... } ⇒ Object
(also: #define_state_machine)
Defines a new machine on a model.
-
#extend_machine(klass, machine_name = 'default') {|StateMachina::Registry.find_machine!(model_name, machine_name)| ... } ⇒ Object
(also: #extend_state_machine)
Extends a machine on a model where the machine is already defined.
-
#machine(machine_name = 'default') ⇒ Object
(also: #state_machine)
Returns the defined machine on a model.
-
#machines ⇒ Object
(also: #state_machines)
Returns the defined machines on a model.
Instance Method Details
#define_machine(machine_name = 'default', column_name: :state, metadata: {}) {|StateMachina::Registry.register_machine(machine)| ... } ⇒ Object Also known as: define_state_machine
Defines a new machine on a model
5 6 7 8 9 10 |
# File 'lib/state_machina/integration.rb', line 5 def define_machine(machine_name = 'default', column_name: :state, metadata: {}) model_name = StateMachina::Util.normalized_klass_to_name(self) machine = StateMachina::Machine.new(model_name, machine_name, column_name: column_name, metadata: ) yield(StateMachina::Registry.register_machine(machine)) end |
#extend_machine(klass, machine_name = 'default') {|StateMachina::Registry.find_machine!(model_name, machine_name)| ... } ⇒ Object Also known as: extend_state_machine
Extends a machine on a model where the machine is already defined
15 16 17 18 19 |
# File 'lib/state_machina/integration.rb', line 15 def extend_machine(klass, machine_name = 'default') model_name = StateMachina::Util.normalized_klass_to_name(klass) yield(StateMachina::Registry.find_machine!(model_name, machine_name)) end |
#machine(machine_name = 'default') ⇒ Object Also known as: state_machine
Returns the defined machine on a model
24 25 26 27 28 |
# File 'lib/state_machina/integration.rb', line 24 def machine(machine_name = 'default') model_name = StateMachina::Util.normalized_klass_to_name(self) StateMachina::Registry.find_machine!(model_name, machine_name) end |
#machines ⇒ Object Also known as: state_machines
Returns the defined machines on a model
33 34 35 36 37 |
# File 'lib/state_machina/integration.rb', line 33 def machines model_name = StateMachina::Util.normalized_klass_to_name(self) StateMachina::Registry.find_machines(model_name) end |