Class: ForemanTasks::ActionRule
- Inherits:
-
Object
- Object
- ForemanTasks::ActionRule
- Defined in:
- lib/foreman_tasks/cleaner.rb
Overview
Represents the cleanup mechanism for tasks
Instance Attribute Summary collapse
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Class Method Summary collapse
Instance Method Summary collapse
- #exclude_search ⇒ Object
- #include_search ⇒ Object
-
#initialize(klass, after, condition = nil) ⇒ ActionRule
constructor
A new instance of ActionRule.
Constructor Details
#initialize(klass, after, condition = nil) ⇒ ActionRule
Returns a new instance of ActionRule.
7 8 9 10 11 |
# File 'lib/foreman_tasks/cleaner.rb', line 7 def initialize(klass, after, condition = nil) @klass = klass @after = after @condition = condition end |
Instance Attribute Details
#after ⇒ Object (readonly)
Returns the value of attribute after.
6 7 8 |
# File 'lib/foreman_tasks/cleaner.rb', line 6 def after @after end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
6 7 8 |
# File 'lib/foreman_tasks/cleaner.rb', line 6 def condition @condition end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
6 7 8 |
# File 'lib/foreman_tasks/cleaner.rb', line 6 def klass @klass end |
Class Method Details
.compose_include_rules(rules) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/foreman_tasks/cleaner.rb', line 27 def self.compose_include_rules(rules) rules.group_by { |rule| [rule.after, rule.condition] } .map do |(after, condition), rules| ActionRule.new(rules.map(&:klass), after, condition) end end |
Instance Method Details
#exclude_search ⇒ Object
13 14 15 |
# File 'lib/foreman_tasks/cleaner.rb', line 13 def exclude_search "NOT (#{include_search})" end |
#include_search ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/foreman_tasks/cleaner.rb', line 17 def include_search parts = if klass.is_a? Array ["label ^ (#{klass.join(', ')})"] else ["label = \"#{klass}\""] end parts << "(#{@condition})" if @condition '(' + parts.join(' AND ') + ')' end |