Top Level Namespace

Defined Under Namespace

Modules: StatefulModelRails

Instance Method Summary collapse

Instance Method Details

#included__stateObject



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/stateful_model_rails/state_machine.rb', line 151

def included__state
  sm_instance = self.class.state_machine_instance
  field_name = sm_instance.field_name

  st = sm_instance.seen_states.detect do |sf|
    sf.name.underscore == attributes[field_name].underscore
  end

  raise StatefulModelRails::MissingStateDefinition, attributes[field_name] if st.nil?

  st.new(self)
end

#included__state_machine(opts = {}) ⇒ Object



142
143
144
145
146
147
148
149
# File 'lib/stateful_model_rails/state_machine.rb', line 142

def included__state_machine(opts = {}, &)
  field_name = opts.fetch(:on, "state").to_s

  @state_machine = StatefulModelRails::StateMachine::StateMachineInternal.new(field_name)
  @state_machine.instance_eval(&)
  @state_machine.install_event_helpers!(self)
  @state_machine
end

#included__state_machine_instanceObject



164
165
166
# File 'lib/stateful_model_rails/state_machine.rb', line 164

def included__state_machine_instance
  @state_machine
end