Class: Tailmix::Definition::Builders::RuleBuilder
- Inherits:
-
Object
- Object
- Tailmix::Definition::Builders::RuleBuilder
- Defined in:
- lib/tailmix/definition/builders/rule_builder.rb
Instance Method Summary collapse
- #build_rule ⇒ Object
- #call(element_name, method_name, *args) ⇒ Object
- #dispatch(event_name, detail: {}) ⇒ Object
-
#initialize(source_state_key) ⇒ RuleBuilder
constructor
A new instance of RuleBuilder.
- #is_not(expected_value) ⇒ Object
- #is_truthy ⇒ Object
- #run(action_name, with: nil) ⇒ Object
- #set_state(payload) ⇒ Object
- #value(expected_value) ⇒ Object (also: #is)
Constructor Details
#initialize(source_state_key) ⇒ RuleBuilder
Returns a new instance of RuleBuilder.
7 8 9 |
# File 'lib/tailmix/definition/builders/rule_builder.rb', line 7 def initialize(source_state_key) @rule = { condition: { type: :eql, source: { type: :state, key: source_state_key } } } end |
Instance Method Details
#build_rule ⇒ Object
44 45 46 |
# File 'lib/tailmix/definition/builders/rule_builder.rb', line 44 def build_rule @rule end |
#call(element_name, method_name, *args) ⇒ Object
40 41 42 |
# File 'lib/tailmix/definition/builders/rule_builder.rb', line 40 def call(element_name, method_name, *args) add_effect(:call_method, element: element_name, method: method_name, args: args) end |
#dispatch(event_name, detail: {}) ⇒ Object
36 37 38 |
# File 'lib/tailmix/definition/builders/rule_builder.rb', line 36 def dispatch(event_name, detail: {}) add_effect(:dispatch_event, name: event_name, detail: detail) end |
#is_not(expected_value) ⇒ Object
17 18 19 20 21 |
# File 'lib/tailmix/definition/builders/rule_builder.rb', line 17 def is_not(expected_value) @rule[:condition][:type] = :not_eql @rule[:condition][:value] = expected_value self end |
#is_truthy ⇒ Object
23 24 25 26 |
# File 'lib/tailmix/definition/builders/rule_builder.rb', line 23 def is_truthy @rule[:condition][:type] = :truthy self end |
#run(action_name, with: nil) ⇒ Object
32 33 34 |
# File 'lib/tailmix/definition/builders/rule_builder.rb', line 32 def run(action_name, with: nil) add_effect(:run_action, name: action_name, with: with) end |
#set_state(payload) ⇒ Object
28 29 30 |
# File 'lib/tailmix/definition/builders/rule_builder.rb', line 28 def set_state(payload) add_effect(:set_state, payload: payload) end |
#value(expected_value) ⇒ Object Also known as: is
11 12 13 14 |
# File 'lib/tailmix/definition/builders/rule_builder.rb', line 11 def value(expected_value) @rule[:condition][:value] = expected_value self end |