Class: Fire::Rule
- Inherits:
-
Object
- Object
- Fire::Rule
- Defined in:
- lib/fire/rule.rb
Overview
Rule class encapsulates a rule definition.
Instance Attribute Summary collapse
-
#logic ⇒ Logic
readonly
Access logic condition.
-
#procedure ⇒ Proc
readonly
Returns [Proc].
Instance Method Summary collapse
-
#apply(&prepare) ⇒ void
(also: #invoke)
Apply logic, running the rule’s prcedure if the logic condition is satisfied.
-
#call(*result_set) ⇒ Object
protected
Run rule procedure.
-
#initialize(logic, options = {}, &procedure) ⇒ Rule
constructor
Initialize new instanance of Rule.
-
#name ⇒ Object
Rules don’t generally have names, but task rules do.
-
#requisite ⇒ Object
(also: #todo)
Names of requisite tasks.
Constructor Details
#initialize(logic, options = {}, &procedure) ⇒ Rule
Initialize new instanance of Rule.
14 15 16 17 18 |
# File 'lib/fire/rule.rb', line 14 def initialize(logic, ={}, &procedure) @logic = logic @requisite = [:todo] @procedure = procedure end |
Instance Attribute Details
#logic ⇒ Logic (readonly)
Access logic condition.
23 24 25 |
# File 'lib/fire/rule.rb', line 23 def logic @logic end |
#procedure ⇒ Proc (readonly)
Returns [Proc]
26 27 28 |
# File 'lib/fire/rule.rb', line 26 def procedure @procedure end |
Instance Method Details
#apply(&prepare) ⇒ void Also known as: invoke
This method returns an undefined value.
Apply logic, running the rule’s prcedure if the logic condition is satisfied.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fire/rule.rb', line 45 def apply(&prepare) case logic when true call when false, nil else result_set = logic.call if result_set && !result_set.empty? prepare.call call(*result_set) end end end |
#call(*result_set) ⇒ Object (protected)
Run rule procedure.
69 70 71 72 73 74 75 76 |
# File 'lib/fire/rule.rb', line 69 def call(*result_set) if @procedure.arity == 0 @procedure.call else #@procedure.call(session, *args) @procedure.call(*result_set) end end |
#name ⇒ Object
Rules don’t generally have names, but task rules do.
37 38 39 |
# File 'lib/fire/rule.rb', line 37 def name nil end |
#requisite ⇒ Object Also known as: todo
Names of requisite tasks.
29 30 31 |
# File 'lib/fire/rule.rb', line 29 def requisite @requisite end |