Class: ForemanTasks::ActionRule

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman_tasks/cleaner.rb

Overview

Represents the cleanup mechanism for tasks

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#afterObject (readonly)

Returns the value of attribute after.



6
7
8
# File 'lib/foreman_tasks/cleaner.rb', line 6

def after
  @after
end

#conditionObject (readonly)

Returns the value of attribute condition.



6
7
8
# File 'lib/foreman_tasks/cleaner.rb', line 6

def condition
  @condition
end

#klassObject (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_searchObject



13
14
15
# File 'lib/foreman_tasks/cleaner.rb', line 13

def exclude_search
  "NOT (#{include_search})"
end

#include_searchObject



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