Class: ManageIQ::Floe::Workflow::ChoiceRule::Data

Inherits:
ManageIQ::Floe::Workflow::ChoiceRule show all
Defined in:
lib/manageiq/floe/workflow/choice_rule/data.rb

Instance Attribute Summary

Attributes inherited from ManageIQ::Floe::Workflow::ChoiceRule

#next, #payload, #variable

Instance Method Summary collapse

Methods inherited from ManageIQ::Floe::Workflow::ChoiceRule

build, #initialize, true?

Constructor Details

This class inherits a constructor from ManageIQ::Floe::Workflow::ChoiceRule

Instance Method Details

#true?(context, input) ⇒ Boolean

Returns:



8
9
10
11
12
13
14
15
16
17
18
19
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
# File 'lib/manageiq/floe/workflow/choice_rule/data.rb', line 8

def true?(context, input)

  lhs = variable_value(context, input)
  rhs = compare_value(context, input)

  validate!(lhs)

  case compare_key
  when "IsNull"; is_null?(lhs)
  when "IsPresent"; is_present?(lhs)
  when "IsNumeric"; is_numeric?(lhs)
  when "IsString"; is_string?(lhs)
  when "IsBoolean"; is_boolean?(lhs)
  when "IsTimestamp"; is_timestamp?(lhs)
  when "StringEquals", "StringEqualsPath",
       "NumericEquals", "NumericEqualsPath",
       "BooleanEquals", "BooleanEqualsPath",
       "TimestampEquals", "TimestampEqualsPath"
    lhs == rhs
  when "StringLessThan", "StringLessThanPath",
       "NumericLessThan", "NumericLessThanPath",
       "TimestampLessThan", "TimestampLessThanPath"
    lhs < rhs
  when "StringGreaterThan", "StringGreaterThanPath",
       "NumericGreaterThan", "NumericGreaterThanPath",
       "TimestampGreaterThan", "TimestampGreaterThanPath"
    lhs > rhs
  when "StringLessThanEquals", "StringLessThanEqualsPath",
       "NumericLessThanEquals", "NumericLessThanEqualsPath",
       "TimestampLessThanEquals", "TimestampLessThanEqualsPath"
    lhs <= rhs
  when "StringGreaterThanEquals", "StringGreaterThanEqualsPath",
       "NumericGreaterThanEquals", "NumericGreaterThanEqualsPath",
       "TimestampGreaterThanEquals", "TimestampGreaterThanEqualsPath"
    lhs >= rhs
  when "StringMatches"
    lhs.match?(Regexp.escape(rhs).gsub('\*','.*?'))
  else
    raise ManageIQ::Floe::InvalidWorkflowError, "Invalid choice [#{compare_key}]"
  end
end