Class: Floe::Workflow::ChoiceRule

Inherits:
Object
  • Object
show all
Includes:
ValidationMixin
Defined in:
lib/floe/workflow/choice_rule.rb,
lib/floe/workflow/choice_rule/or.rb,
lib/floe/workflow/choice_rule/and.rb,
lib/floe/workflow/choice_rule/not.rb,
lib/floe/workflow/choice_rule/data.rb

Direct Known Subclasses

And, Data, Not, Or

Defined Under Namespace

Classes: And, Data, Not, Or

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ValidationMixin

included, #invalid_field_error!, #missing_field_error!, #parser_error!, #runtime_field_error!, #workflow_state?, #wrap_parser_error

Constructor Details

#initialize(workflow, name, payload, children = nil) ⇒ ChoiceRule

Returns a new instance of ChoiceRule.



32
33
34
35
36
37
38
39
# File 'lib/floe/workflow/choice_rule.rb', line 32

def initialize(workflow, name, payload, children = nil)
  @name      = name
  @payload   = payload
  @children  = children
  @next      = payload["Next"]

  validate_next!(workflow)
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



30
31
32
# File 'lib/floe/workflow/choice_rule.rb', line 30

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



30
31
32
# File 'lib/floe/workflow/choice_rule.rb', line 30

def name
  @name
end

#nextObject (readonly)

Returns the value of attribute next.



30
31
32
# File 'lib/floe/workflow/choice_rule.rb', line 30

def next
  @next
end

#payloadObject (readonly)

Returns the value of attribute payload.



30
31
32
# File 'lib/floe/workflow/choice_rule.rb', line 30

def payload
  @payload
end

Class Method Details

.build(workflow, name, payload) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/floe/workflow/choice_rule.rb', line 9

def build(workflow, name, payload)
  if (sub_payloads = payload["Not"])
    name += ["Not"]
    Floe::Workflow::ChoiceRule::Not.new(workflow, name, payload, build_children(workflow, name, [sub_payloads]))
  elsif (sub_payloads = payload["And"])
    name += ["And"]
    Floe::Workflow::ChoiceRule::And.new(workflow, name, payload, build_children(workflow, name, sub_payloads))
  elsif (sub_payloads = payload["Or"])
    name += ["Or"]
    Floe::Workflow::ChoiceRule::Or.new(workflow, name, payload, build_children(workflow, name, sub_payloads))
  else
    name += ["Data"]
    Floe::Workflow::ChoiceRule::Data.new(workflow, name, payload)
  end
end

.build_children(workflow, name, sub_payloads) ⇒ Object



25
26
27
# File 'lib/floe/workflow/choice_rule.rb', line 25

def build_children(workflow, name, sub_payloads)
  sub_payloads.map.with_index { |payload, i| build(workflow, name + [i.to_s], payload) }
end

Instance Method Details

#true?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/floe/workflow/choice_rule.rb', line 41

def true?(*)
  raise NotImplementedError, "Must be implemented in a subclass"
end