Class: StateFlow::Element
- Inherits:
-
Object
- Object
- StateFlow::Element
- Includes:
- ElementVisitable
- Defined in:
- lib/state_flow/element.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
Class Method Summary collapse
Instance Method Summary collapse
- #flow ⇒ Object
-
#initialize(origin, &block) ⇒ Element
constructor
A new instance of Element.
- #inspect ⇒ Object
- #retry_in_recovering(context) ⇒ Object
- #state ⇒ Object
- #to(destination) ⇒ Object
- #update_to_destination(context) ⇒ Object
Methods included from ElementVisitable
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
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
9 10 11 |
# File 'lib/state_flow/element.rb', line 9 def destination @destination end |
#origin ⇒ Object (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_vars ⇒ Object
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
#flow ⇒ Object
19 20 21 |
# File 'lib/state_flow/element.rb', line 19 def flow @flow || origin.flow end |
#inspect ⇒ Object
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 |
#state ⇒ Object
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 |