Class: Riptables::Rule
- Inherits:
-
Object
- Object
- Riptables::Rule
- Defined in:
- lib/riptables/rule.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#chain ⇒ Object
readonly
Returns the value of attribute chain.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#description ⇒ Object
Returns the value of attribute description.
-
#permutations ⇒ Object
readonly
Returns the value of attribute permutations.
-
#rule ⇒ Object
Returns the value of attribute rule.
-
#versions ⇒ Object
Returns the value of attribute versions.
Instance Method Summary collapse
- #dsl ⇒ Object
- #dup ⇒ Object
- #include?(conditions) ⇒ Boolean
-
#initialize(chain) ⇒ Rule
constructor
A new instance of Rule.
- #permuted_rules ⇒ Object
Constructor Details
#initialize(chain) ⇒ Rule
6 7 8 9 10 11 |
# File 'lib/riptables/rule.rb', line 6 def initialize(chain) @chain = chain @permutations = [] @conditions = Condition.conditions.dup @versions = [4, 6] end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
15 16 17 |
# File 'lib/riptables/rule.rb', line 15 def action @action end |
#chain ⇒ Object (readonly)
Returns the value of attribute chain.
18 19 20 |
# File 'lib/riptables/rule.rb', line 18 def chain @chain end |
#conditions ⇒ Object
Returns the value of attribute conditions.
16 17 18 |
# File 'lib/riptables/rule.rb', line 16 def conditions @conditions end |
#description ⇒ Object
Returns the value of attribute description.
13 14 15 |
# File 'lib/riptables/rule.rb', line 13 def description @description end |
#permutations ⇒ Object (readonly)
Returns the value of attribute permutations.
19 20 21 |
# File 'lib/riptables/rule.rb', line 19 def permutations @permutations end |
#rule ⇒ Object
Returns the value of attribute rule.
14 15 16 |
# File 'lib/riptables/rule.rb', line 14 def rule @rule end |
#versions ⇒ Object
Returns the value of attribute versions.
17 18 19 |
# File 'lib/riptables/rule.rb', line 17 def versions @versions end |
Instance Method Details
#dsl ⇒ Object
21 22 23 |
# File 'lib/riptables/rule.rb', line 21 def dsl @dsl ||= DSL::Rule.new(self) end |
#dup ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/riptables/rule.rb', line 37 def dup new_rule = self.class.new(self.chain) new_rule.description = self.description.dup if self.description new_rule.rule = self.rule.dup if self.rule new_rule.action = self.action if self.action new_rule.conditions = self.conditions.dup if self.conditions new_rule end |
#include?(conditions) ⇒ Boolean
25 26 27 |
# File 'lib/riptables/rule.rb', line 25 def include?(conditions) @conditions.all? { |c| c.matches?(conditions) } end |
#permuted_rules ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/riptables/rule.rb', line 29 def permuted_rules if permutations.empty? [self] else permutations.map(&:to_rules).flatten end end |