Class: StateFlow::Element

Inherits:
Object
  • Object
show all
Includes:
ElementVisitable
Defined in:
lib/state_flow/element.rb

Direct Known Subclasses

Action, Event, Guard

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ElementVisitable

#visit

Constructor Details

#initialize(origin, &block) ⇒ Element

Returns a new instance of Element.



10
11
12
13
# File 'lib/state_flow/element.rb', line 10

def initialize(origin, &block)
  @origin = origin
  instance_eval(&block) if block
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



9
10
11
# File 'lib/state_flow/element.rb', line 9

def destination
  @destination
end

#originObject (readonly)

Returns the value of attribute origin.



8
9
10
# File 'lib/state_flow/element.rb', line 8

def origin
  @origin
end

Class Method Details

.uninspected_var(*vars) ⇒ Object



39
40
41
42
43
# File 'lib/state_flow/element.rb', line 39

def uninspected_var(*vars)
  @@uninspected_var_hash ||= {}
  @@uninspected_var_hash[self] ||= []
  @@uninspected_var_hash[self].concat(vars.map{|v| v.to_s.sub(/^([^@])/){"@#{$1}"}})
end

.uninspected_varsObject



45
46
47
48
# File 'lib/state_flow/element.rb', line 45

def uninspected_vars
  @uninspected_vars ||= @@uninspected_var_hash.nil? ? %w(@flow @origin) :
    self.ancestors.map{|klass| @@uninspected_var_hash[klass] || []}.flatten
end

Instance Method Details

#flowObject



19
20
21
# File 'lib/state_flow/element.rb', line 19

def flow
  @flow || origin.flow
end

#inspectObject



52
53
54
55
56
57
58
59
# File 'lib/state_flow/element.rb', line 52

def inspect
  vars = (instance_variables - self.class.uninspected_vars).map do |name|
    "#{name}=#{instance_variable_get(name).inspect}"
  end
  # vars = []
  vars.unshift("%s:%#x" % [self.class.name, self.object_id])
  "#<#{vars.join(' ')}>"
end

#retry_in_recovering(context) ⇒ Object



33
34
35
# File 'lib/state_flow/element.rb', line 33

def retry_in_recovering(context)
  update_to_destination(context)
end

#stateObject



23
24
25
# File 'lib/state_flow/element.rb', line 23

def state
  origin.is_a?(State) ? origin : origin.state
end

#to(destination) ⇒ Object



15
16
17
# File 'lib/state_flow/element.rb', line 15

def to(destination)
  @destination = destination
end

#update_to_destination(context) ⇒ Object



27
28
29
30
31
# File 'lib/state_flow/element.rb', line 27

def update_to_destination(context)
  return unless destination
  context.mark_proceeding
  context.record_send("#{flow.attr_key_name}=", destination)
end