Class: Fabulator::Core::Structurals::Transition
- Inherits:
-
Structural
- Object
- Action
- Structural
- Fabulator::Core::Structurals::Transition
- Defined in:
- lib/fabulator/core/structurals/transition.rb
Instance Attribute Summary collapse
-
#state ⇒ Object
Returns the value of attribute state.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#validations ⇒ Object
Returns the value of attribute validations.
Instance Method Summary collapse
- #apply_constraints(ctx) ⇒ Object
- #apply_filters(ctx) ⇒ Object
- #param_names ⇒ Object
- #run(context) ⇒ Object
- #validate_params(context, params) ⇒ 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
#state ⇒ Object
Returns the value of attribute state.
5 6 7 |
# File 'lib/fabulator/core/structurals/transition.rb', line 5 def state @state end |
#tags ⇒ Object
Returns the value of attribute tags.
5 6 7 |
# File 'lib/fabulator/core/structurals/transition.rb', line 5 def @tags end |
#validations ⇒ Object
Returns the value of attribute validations.
5 6 7 |
# File 'lib/fabulator/core/structurals/transition.rb', line 5 def validations @validations end |
Instance Method Details
#apply_constraints(ctx) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/fabulator/core/structurals/transition.rb', line 89 def apply_constraints(ctx) invalid = [ ] missing = [ ] valid = [ ] msgs = [ ] @params.each do |p| res = p.apply_constraints(ctx) invalid = invalid + res[:invalid] missing = missing + res[:missing] valid = valid + res[:valid] msgs = msgs + res[:messages] end return { :missing => missing, :invalid => invalid, :valid => valid, :messages => msgs, :unknown => [ ] } end |
#apply_filters(ctx) ⇒ Object
83 84 85 86 87 |
# File 'lib/fabulator/core/structurals/transition.rb', line 83 def apply_filters(ctx) @params.collect { |p| p.apply_filters(ctx) }.flatten end |
#param_names ⇒ Object
16 17 18 |
# File 'lib/fabulator/core/structurals/transition.rb', line 16 def param_names (@params.collect{|w| w.param_names}.flatten).uniq end |
#run(context) ⇒ Object
104 105 106 107 108 |
# File 'lib/fabulator/core/structurals/transition.rb', line 104 def run(context) # do queries, denials, assertions in the order given @actions.run(@context.merge(context)) return [] end |
#validate_params(context, params) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/fabulator/core/structurals/transition.rb', line 20 def validate_params(context,params) ctx = @context.merge(context) my_params = params param_context = Fabulator::Expr::Node.new( 'ext', ctx.root.roots, nil, [] ) ctx.root.roots['ext'] = param_context p_ctx = ctx.with_root(param_context) p_ctx.merge_data(my_params) if @select.nil? self.apply_filters(p_ctx) else @select.run(p_ctx).each{ |c| self.apply_filters(p_ctx.with_root(c)) } end res = { :unknown => [ ], :valid => [ ], :invalid => [ ], :missing => [ ], :messages => [ ], } if @select.nil? rr = self.apply_constraints(p_ctx) res[:invalid] += rr[:invalid] res[:valid] += rr[:valid] res[:unknown] += rr[:unknown] res[:messages] += rr[:messages] else @select.run(p_ctx).each do |c| rr = self.apply_constraints(p_ctx.with_root(c)) res[:invalid] += rr[:invalid] res[:valid] += rr[:valid] res[:unknown] += rr[:unknown] res[:messages] += rr[:messages] end end res[:unknown] = [ ] res[:invalid].uniq! res[:invalid].each do |k| res[:valid].delete(k.path) res[:unknown].delete(k.path) end #res[:unknown] = res[:unknown].collect{|k| @select + k} res[:unknown].each do |k| res[:valid].delete(k) end res[:score] = (res[:valid].size+1)*(params.size) / (res[:missing].size + 1) / (res[:invalid].size + 1) / (res[:unknown].size + 1) return res end |