Class: StatefulModelRails::StateMachine::State

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ State

Returns a new instance of State.



11
12
13
# File 'lib/stateful_model_rails/state_machine.rb', line 11

def initialize(parent)
  @parent = parent
end

Class Attribute Details

.after_enter_callbacksObject (readonly)

Returns the value of attribute after_enter_callbacks.



6
7
8
# File 'lib/stateful_model_rails/state_machine.rb', line 6

def after_enter_callbacks
  @after_enter_callbacks
end

.after_leave_callbacksObject (readonly)

Returns the value of attribute after_leave_callbacks.



6
7
8
# File 'lib/stateful_model_rails/state_machine.rb', line 6

def after_leave_callbacks
  @after_leave_callbacks
end

.before_enter_callbacksObject (readonly)

Returns the value of attribute before_enter_callbacks.



6
7
8
# File 'lib/stateful_model_rails/state_machine.rb', line 6

def before_enter_callbacks
  @before_enter_callbacks
end

.before_leave_callbacksObject (readonly)

Returns the value of attribute before_leave_callbacks.



6
7
8
# File 'lib/stateful_model_rails/state_machine.rb', line 6

def before_leave_callbacks
  @before_leave_callbacks
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



9
10
11
# File 'lib/stateful_model_rails/state_machine.rb', line 9

def parent
  @parent
end

Class Method Details

.after_enter(&block) ⇒ Object



30
31
32
33
# File 'lib/stateful_model_rails/state_machine.rb', line 30

def self.after_enter(&block)
  @after_enter_callbacks ||= []
  @after_enter_callbacks << block
end

.after_leave(&block) ⇒ Object



20
21
22
23
# File 'lib/stateful_model_rails/state_machine.rb', line 20

def self.after_leave(&block)
  @after_leave_callbacks ||= []
  @after_leave_callbacks << block
end

.before_enter(&block) ⇒ Object



25
26
27
28
# File 'lib/stateful_model_rails/state_machine.rb', line 25

def self.before_enter(&block)
  @before_enter_callbacks ||= []
  @before_enter_callbacks << block
end

.before_leave(&block) ⇒ Object



15
16
17
18
# File 'lib/stateful_model_rails/state_machine.rb', line 15

def self.before_leave(&block)
  @before_leave_callbacks ||= []
  @before_leave_callbacks << block
end

Instance Method Details

#nameObject



59
60
61
# File 'lib/stateful_model_rails/state_machine.rb', line 59

def name
  self.class.name
end

#run_after_enterObject



53
54
55
56
57
# File 'lib/stateful_model_rails/state_machine.rb', line 53

def run_after_enter
  return unless self.class.after_enter_callbacks

  self.class.after_enter_callbacks.each { |b| parent.instance_exec(self, &b) }
end

#run_after_leaveObject



41
42
43
44
45
# File 'lib/stateful_model_rails/state_machine.rb', line 41

def run_after_leave
  return unless self.class.after_leave_callbacks

  self.class.after_leave_callbacks.each { |b| parent.instance_exec(self, &b) }
end

#run_before_enterObject



47
48
49
50
51
# File 'lib/stateful_model_rails/state_machine.rb', line 47

def run_before_enter
  return unless self.class.before_enter_callbacks

  self.class.before_enter_callbacks.each { |b| parent.instance_exec(self, &b) }
end

#run_before_leaveObject



35
36
37
38
39
# File 'lib/stateful_model_rails/state_machine.rb', line 35

def run_before_leave
  return unless self.class.before_leave_callbacks

  self.class.before_leave_callbacks.each { |b| parent.instance_exec(self, &b) }
end