Module: StateMachina::Integration

Defined in:
lib/state_machina/integration.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Object



42
43
44
# File 'lib/state_machina/integration.rb', line 42

def self.included(model)
  model.extend(StateMachina::Integration::ClassMethods)
end

Instance Method Details

#machine(machine_name = 'default') ⇒ Object Also known as: state_machine

Returns the defined machine on a model instance



47
48
49
50
51
52
53
# File 'lib/state_machina/integration.rb', line 47

def machine(machine_name = 'default')
  model_name = StateMachina::Util.normalized_klass_to_name(self.class)

  machine = StateMachina::Registry.find_machine!(model_name, machine_name).dup
  machine.model = self
  machine
end

#machinesObject Also known as: state_machines

Returns the defined machines on a model instance



58
59
60
61
62
63
64
65
66
# File 'lib/state_machina/integration.rb', line 58

def machines
  model_name = StateMachina::Util.normalized_klass_to_name(self.class)

  machines = StateMachina::Registry.find_machines(model_name).map(&:dup)
  machines.map do |machine|
    machine.model = self
    machine
  end
end