Class: SimpleStateMachine::Decorator

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_state_machine/simple_state_machine.rb

Overview

Decorates @subject with methods to access the state machine

Direct Known Subclasses

ActiveRecord::Decorator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject) ⇒ Decorator

Returns a new instance of Decorator.



215
216
217
218
219
220
# File 'lib/simple_state_machine/simple_state_machine.rb', line 215

def initialize(subject)
  @subject = subject
  define_state_machine_method
  define_state_getter_method
  define_state_setter_method
end

Instance Attribute Details

#subject=(value) ⇒ Object (writeonly)

Sets the attribute subject

Parameters:

  • value

    the value to set the attribute subject to.



214
215
216
# File 'lib/simple_state_machine/simple_state_machine.rb', line 214

def subject=(value)
  @subject = value
end

Instance Method Details

#decorate(transition) ⇒ Object



222
223
224
225
226
227
# File 'lib/simple_state_machine/simple_state_machine.rb', line 222

def decorate transition
  define_state_helper_method(transition.from)
  define_state_helper_method(transition.to)
  define_event_method(transition.event_name)
  decorate_event_method(transition.event_name)
end