Class: StateFlow::State
- Inherits:
-
Object
- Object
- StateFlow::State
- Includes:
- ActionClient, ElementVisitable, EventClient, GuardClient
- Defined in:
- lib/state_flow/state.rb
Instance Attribute Summary collapse
-
#flow ⇒ Object
readonly
Returns the value of attribute flow.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#termination(name = nil) ⇒ Object
Returns the value of attribute termination.
Instance Method Summary collapse
- #children ⇒ Object
- #concrete? ⇒ Boolean
- #descendants ⇒ Object
-
#exception_handlers ⇒ Object
override ExceptionHandlerClient#exception_handlers.
- #include?(state_or_name) ⇒ Boolean
-
#initialize(flow_or_parent, name, &block) ⇒ State
constructor
A new instance of State.
- #inspect ⇒ Object
- #name_path(separator = '>') ⇒ Object
- #process(context) ⇒ Object
- #state(name, &block) ⇒ Object (also: #from, #group, #state_group)
Methods included from ElementVisitable
Methods included from ActionClient
Methods included from GuardClient
#guard, #guard_else, #guard_for, #guards
Methods included from EventClient
#action_event, #event, #event_else, #event_for_action_result, #events, #handle_exception, #named_event, #recover
Methods included from ExceptionHandlerClient
Constructor Details
#initialize(flow_or_parent, name, &block) ⇒ State
Returns a new instance of State.
13 14 15 16 17 18 19 |
# File 'lib/state_flow/state.rb', line 13 def initialize(flow_or_parent, name, &block) @name = name @parent = flow_or_parent if flow_or_parent.is_a?(State) @flow = flow_or_parent.is_a?(State) ? flow_or_parent.flow : flow_or_parent @concreate = @flow.state_cd_by_key(@name) instance_eval(&block) if block end |
Instance Attribute Details
#flow ⇒ Object (readonly)
Returns the value of attribute flow.
11 12 13 |
# File 'lib/state_flow/state.rb', line 11 def flow @flow end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/state_flow/state.rb', line 11 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
11 12 13 |
# File 'lib/state_flow/state.rb', line 11 def parent @parent end |
#termination(name = nil) ⇒ Object
Returns the value of attribute termination.
12 13 14 |
# File 'lib/state_flow/state.rb', line 12 def termination @termination end |
Instance Method Details
#children ⇒ Object
36 37 38 |
# File 'lib/state_flow/state.rb', line 36 def children @children ||= [] end |
#concrete? ⇒ Boolean
49 50 51 |
# File 'lib/state_flow/state.rb', line 49 def concrete? @concreate end |
#descendants ⇒ Object
40 41 42 |
# File 'lib/state_flow/state.rb', line 40 def descendants [self, children.map{|c|c.descendants}].flatten end |
#exception_handlers ⇒ Object
override ExceptionHandlerClient#exception_handlers
70 71 72 73 74 |
# File 'lib/state_flow/state.rb', line 70 def exception_handlers result = events.select{|ev| ev.is_a?(ExceptionHandler)} result.concat(parent.exception_handlers) if parent result end |
#include?(state_or_name) ⇒ Boolean
44 45 46 47 |
# File 'lib/state_flow/state.rb', line 44 def include?(state_or_name) name = state_or_name.is_a?(State) ? state_or_name.name : state_or_name descendants.any?{|state| state.name == name} end |
#inspect ⇒ Object
86 87 88 |
# File 'lib/state_flow/state.rb', line 86 def inspect "#<%s:%#x @name=%s>" % [self.class.name, self.object_id, name_path.inspect] end |
#name_path(separator = '>') ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/state_flow/state.rb', line 76 def name_path(separator = '>') result = [] current = self while current result << current.name current = current.parent end result.reverse.join(separator) end |
#process(context) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/state_flow/state.rb', line 60 def process(context) context.trace(self) exception_handling(context) do guard = guard_for(context) return guard.process(context) if guard return action.process(context) if action end end |