Sha256: 137349cfc6f9db4b37b0c761f747c5d01e695d412a65918453c4de61bd189fef

Contents?: true

Size: 1.33 KB

Versions: 53

Compression:

Stored size: 1.33 KB

Contents

module ForemanTasks
  module Concerns
    module ActionSubject

      extend ActiveSupport::Concern

      module ClassMethods
        def available_locks
          [:read, :write]
        end
      end

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

      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

      # @api override to return the objects that relate to this one, usually parent
      # 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.
      def related_resources
        []
      end

      # Recursively searches for related resources of this one, avoiding cycles
      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

    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
foreman-tasks-0.8.6 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.8.5 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.8.4 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.8.3 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.8.2 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.8.1 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.8.0 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.7.20 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.7.19 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.7.18 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.7.17 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.7.16 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.7.15 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.7.14 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.7.13 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.7.12 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.7.11 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.7.10 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.7.9 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.7.8 app/models/foreman_tasks/concerns/action_subject.rb