Module: Ruote::Exp::Condition
- Defined in:
- lib/ruote/exp/condition.rb
Overview
A few helper methods for evaluating :if and :unless expression attributes in process definitions.
Defined Under Namespace
Classes: ConditionError
Constant Summary collapse
- REGEXES =
{ 'evl_set' => /^(.+?)( +is)?( +not)?( +set)$/, 'evl_null' => /^(.+?)( +is)?( +not)?( +null)$/, 'evl_empty' => /^(.+[\]}"'])( +is)?( +not)?( +empty)$/, 'evl_in' => /^(.+?)( +is)?( +not)?( +in +)(\[.*\]|\{.*\})$/ }
Class Method Summary collapse
- .apply?(sif, sunless) ⇒ Boolean
-
.eval(code) ⇒ Object
Evaluates the given [conditional] code string and returns the result.
-
.true?(conditional) ⇒ Boolean
Returns true if the given conditional string evaluates to true.
Class Method Details
.apply?(sif, sunless) ⇒ Boolean
53 54 55 56 57 58 59 |
# File 'lib/ruote/exp/condition.rb', line 53 def self.apply?(sif, sunless) return (true?(sif)) if sif return ( ! true?(sunless)) if sunless true end |
.eval(code) ⇒ Object
Evaluates the given [conditional] code string and returns the result.
Note : this is not a full Ruby evaluation !
85 86 87 88 89 90 91 92 |
# File 'lib/ruote/exp/condition.rb', line 85 def self.eval(code) evl(code) rescue ArgumentError => ae raise ConditionError.new(code) end |
.true?(conditional) ⇒ Boolean
Returns true if the given conditional string evaluates to true.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruote/exp/condition.rb', line 63 def self.true?(conditional) conditional = unescape(conditional.to_s) REGEXES.each do |method, regex| if m = regex.match(conditional) return self.send(method, m) end end evl(conditional) ? true : false rescue ArgumentError => ae raise ConditionError.new(conditional) end |