Sha256: 4e9e5b7fb07b388b3c1864f1429905a9e652aa7bec3d36bbea288dfd26961fe5

Contents?: true

Size: 1.33 KB

Versions: 76

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 new_record?

        { id: id, name: name }.tap do |hash|
          hash.update(label: label) if 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 = 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
    end
  end
end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
foreman-tasks-0.15.1 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.15.0 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.14.5 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.14.4 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.14.3 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.14.2 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.14.1 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.11.3 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.14.0 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.13.4 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.13.3 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.13.2 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.13.1 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.13.0 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.12.2 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.11.2 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.12.1 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.12.0 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.11.1 app/models/foreman_tasks/concerns/action_subject.rb
foreman-tasks-0.10.9 app/models/foreman_tasks/concerns/action_subject.rb