Module: ForemanTasks::Concerns::ActionSubject

Extended by:
ActiveSupport::Concern
Included in:
HostActionSubject
Defined in:
app/models/foreman_tasks/concerns/action_subject.rb

Instance Method Summary collapse

Instance Method Details

#action_input_keyObject



6
7
8
# File 'app/models/foreman_tasks/concerns/action_subject.rb', line 6

def action_input_key
  self.class.name.demodulize.underscore
end

Recursively searches for related resources of this one, avoiding cycles



29
30
31
32
33
34
35
36
37
# File 'app/models/foreman_tasks/concerns/action_subject.rb', line 29

def all_related_resources
  mine = Set.new Array(related_resources)

  get_all_related_resources = lambda do |resource|
    resource.is_a?(ActionSubject) ? resource.all_related_resources : []
  end

  mine + mine.reduce(Set.new) { |s, resource| s + get_all_related_resources.call(resource) }
end

objects, e.g. repository would return product it belongs to, product would return provider etc.

It’s used to link a task running on top of this resource to it’s related objects, so that is’t possible to see all the sync tasks for a product etc.



24
25
26
# File 'app/models/foreman_tasks/concerns/action_subject.rb', line 24

def related_resources
  []
end

#to_action_inputObject



10
11
12
13
14
15
16
# File 'app/models/foreman_tasks/concerns/action_subject.rb', line 10

def to_action_input
  raise 'The resource needs to be saved first' if new_record?

  { id: id, name: name }.tap do |hash|
    hash.update(label: label) if respond_to? :label
  end
end