Class: Fabulator::Core::Structurals::State
- Inherits:
-
Structural
- Object
- Action
- Structural
- Fabulator::Core::Structurals::State
- Defined in:
- lib/fabulator/core/structurals/state.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#transitions ⇒ Object
Returns the value of attribute transitions.
Instance Method Summary collapse
- #run_post(context) ⇒ Object
- #run_pre(context) ⇒ Object
- #select_transition(context, params) ⇒ Object
- #states ⇒ Object
Methods inherited from Structural
#accepts_structural?, accepts_structural?, #compile_xml, contained_in, contains, element, #initialize, structurals
Constructor Details
This class inherits a constructor from Fabulator::Structural
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/fabulator/core/structurals/state.rb', line 5 def name @name end |
#transitions ⇒ Object
Returns the value of attribute transitions.
5 6 7 |
# File 'lib/fabulator/core/structurals/state.rb', line 5 def transitions @transitions end |
Instance Method Details
#run_post(context) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/fabulator/core/structurals/state.rb', line 44 def run_post(context) # do queries, denials, assertions in the order given ctx = context.class.new(@context, context) @post_actions.run(ctx) unless @post_actions.nil? return [] end |
#run_pre(context) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/fabulator/core/structurals/state.rb', line 37 def run_pre(context) # do queries, denials, assertions in the order given ctx = context.class.new(@context, context) @pre_actions.run(ctx) unless @pre_actions.nil? return [] end |
#select_transition(context, params) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fabulator/core/structurals/state.rb', line 17 def select_transition(context,params) # we need hypthetical variables here :-/ return nil if @context.nil? best_match = nil @context.with(context) do |ctx| best_match = nil @transitions.each do |t| res = t.validate_params(ctx,params) if res[:missing].empty? && res[:messages].empty? && res[:unknown].empty? && res[:invalid].empty? res[:transition] = t end if best_match.nil? || res[:score] > best_match[:score] best_match = res best_match[:transition] = t end end end return best_match end |
#states ⇒ Object
13 14 15 |
# File 'lib/fabulator/core/structurals/state.rb', line 13 def states @transitions.map { |t| t.state }.uniq end |