Module: ForemanTasks::Concerns::ActionSubject

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

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#action_input_keyObject



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

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

Recursively searches for related resources of this one, avoiding cycles



36
37
38
39
40
41
42
43
44
# File 'app/models/foreman_tasks/concerns/action_subject.rb', line 36

def all_related_resources
  mine = Set.new Array(related_resources)

  get_all_related_resources = -> resource do
    resource.is_a?(ActionSubject) ? resource.all_related_resources : []
  end

  mine + mine.reduce(Set.new) { |s, resource| s + get_all_related_resources.(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.



31
32
33
# File 'app/models/foreman_tasks/concerns/action_subject.rb', line 31

def related_resources
  []
end

#to_action_inputObject



17
18
19
20
21
22
23
# File 'app/models/foreman_tasks/concerns/action_subject.rb', line 17

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

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