Class: ForemanTasks::Link

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/foreman_tasks/link.rb

Class Method Summary collapse

Class Method Details



35
36
37
38
39
# File 'app/models/foreman_tasks/link.rb', line 35

def build_related_links(resource, task)
  related_resources(resource).map do |related_resource|
    build(related_resource, task)
  end
end

.link!(resource, task) ⇒ Object

Assigns the resource to the task to easily track the task in context of the resource. This doesn’t prevent other actions to lock the resource and should be used only for actions that tolerate other actions to be performed on the resource. Usually, this shouldn’t needed to be done through the action directly, because the lock should assign it’s parent objects to the action recursively (using related_resources method in model objects)



19
20
21
22
23
# File 'app/models/foreman_tasks/link.rb', line 19

def link!(resource, task)
  link = build(resource, task)
  link.save!
  link
end


30
31
32
33
# File 'app/models/foreman_tasks/link.rb', line 30

def link_resource_and_related!(resource, task)
  link!(resource, task)
  build_related_links(resource, task).each(&:save!)
end

.owner!(user, task) ⇒ Object

Records the information about the user that triggered the task



26
27
28
# File 'app/models/foreman_tasks/link.rb', line 26

def owner!(user, task)
  link!(user, task)
end