Class: Noteikumi::RuleConditionValidator Private
- Inherits:
-
Object
- Object
- Noteikumi::RuleConditionValidator
- Defined in:
- lib/noteikumi/rule_condition_validator.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This is a class used by Noteikumi::Rule#satisfies_run_condition? to create a clean room to evaluate the state conditions in and provides helpers to expose named conditions as methods for use by Noteikumi::Rule#run_when
Instance Method Summary collapse
-
#__condition(condition) ⇒ Proc?
private
Retrieves a named condition from the rule.
-
#__evaluate_condition(condition, *args) ⇒ Boolean
private
Evaluate a named condition.
-
#__known_condition?(condition) ⇒ Boolean
private
Determines if the rule has a condition by name.
-
#__should_run? ⇒ Boolean
private
Runs the rules run condition.
-
#first_run? ⇒ Boolean
private
Checks if this is the first time the rule is being ran.
-
#initialize(rule) ⇒ RuleConditionValidator
constructor
private
Creates a new validator.
-
#method_missing(method, *args, &blk) ⇒ Boolean
private
Provide method access to named based conditions.
-
#state_had_failures? ⇒ Boolean
private
Checks if the state had any past failures.
-
#state_processed_by?(rule) ⇒ Boolean
private
Checks if a rule with a specific name acted on the state.
Constructor Details
#initialize(rule) ⇒ RuleConditionValidator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new validator
12 13 14 |
# File 'lib/noteikumi/rule_condition_validator.rb', line 12 def initialize(rule) @__rule = rule end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Provide method access to named based conditions
77 78 79 80 81 82 83 |
# File 'lib/noteikumi/rule_condition_validator.rb', line 77 def method_missing(method, *args, &blk) if __known_condition?(method) __evaluate_condition(method, *args) else super end end |
Instance Method Details
#__condition(condition) ⇒ Proc?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Retrieves a named condition from the rule
57 58 59 |
# File 'lib/noteikumi/rule_condition_validator.rb', line 57 def __condition(condition) @__rule.conditions[condition] end |
#__evaluate_condition(condition, *args) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Evaluate a named condition
66 67 68 69 70 |
# File 'lib/noteikumi/rule_condition_validator.rb', line 66 def __evaluate_condition(condition, *args) result = !!__condition(condition).call(*args) @__rule.logger.debug("Condition %s returned %s on %s" % [condition, result.inspect, @__rule]) result end |
#__known_condition?(condition) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determines if the rule has a condition by name
49 50 51 |
# File 'lib/noteikumi/rule_condition_validator.rb', line 49 def __known_condition?(condition) @__rule.has_condition?(condition) end |
#__should_run? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs the rules run condition
41 42 43 |
# File 'lib/noteikumi/rule_condition_validator.rb', line 41 def __should_run? instance_eval(&@__rule.run_condition) end |
#first_run? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if this is the first time the rule is being ran
19 20 21 |
# File 'lib/noteikumi/rule_condition_validator.rb', line 19 def first_run? @__rule.run_count == 0 end |
#state_had_failures? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if the state had any past failures
26 27 28 |
# File 'lib/noteikumi/rule_condition_validator.rb', line 26 def state_had_failures? @__rule.state.had_failures? end |
#state_processed_by?(rule) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if a rule with a specific name acted on the state
34 35 36 |
# File 'lib/noteikumi/rule_condition_validator.rb', line 34 def state_processed_by?(rule) @__rule.state.processed_by?(rule) end |