Sha256: 63a38c973f4ba5ec3f7db6fdb12072136a5c08de725d251d651c17bde6c827c6

Contents?: true

Size: 1.13 KB

Versions: 136

Compression:

Stored size: 1.13 KB

Contents

module Eco
  module API
    # @todo the autoloading happens on `add`, and there could be multiple pending children to load.
    #   This could translate into the policies not being loaded in order
    class Policies < Eco::API::UseCases
      autoloads_children_of "Eco::API::Common::Loaders::Policy"
      autoload_namespace_ignore "Eco::API"

      attr_reader :policies

      def define(name, type: :transform, &block)
        Eco::API::Policies::Policy.new(name, type: type, root: self, &block).tap do |policy|
          add(policy)
        end
      end

      def add(policy)
        raise "Expected Eco::API::Policies::Policy object. Given: #{policy}" unless policy.is_a?(Eco::API::Policies::Policy)
        super(policy)
      end

      def launch(people:, session:, job:, options: {})
        args = {
          people:  people,
          session: session,
          job:     job,
          options: options
        }

        items.map do |policy|
          policy.launch(**args)
        end
      end
    end
  end
end

require_relative 'policies/policy'
require_relative 'policies/default_policies'

Version data entries

136 entries across 136 versions & 1 rubygems

Version Path
eco-helpers-2.5.1 lib/eco/api/policies.rb
eco-helpers-2.4.9 lib/eco/api/policies.rb
eco-helpers-2.4.8 lib/eco/api/policies.rb
eco-helpers-2.4.7 lib/eco/api/policies.rb
eco-helpers-2.4.6 lib/eco/api/policies.rb
eco-helpers-2.4.5 lib/eco/api/policies.rb
eco-helpers-2.4.4 lib/eco/api/policies.rb
eco-helpers-2.4.3 lib/eco/api/policies.rb
eco-helpers-2.4.2 lib/eco/api/policies.rb
eco-helpers-2.3.3 lib/eco/api/policies.rb
eco-helpers-2.3.2 lib/eco/api/policies.rb
eco-helpers-2.2.5 lib/eco/api/policies.rb
eco-helpers-2.2.4 lib/eco/api/policies.rb
eco-helpers-2.2.3 lib/eco/api/policies.rb
eco-helpers-2.2.2 lib/eco/api/policies.rb
eco-helpers-2.2.1 lib/eco/api/policies.rb
eco-helpers-2.1.12 lib/eco/api/policies.rb
eco-helpers-2.1.11 lib/eco/api/policies.rb
eco-helpers-2.1.10 lib/eco/api/policies.rb
eco-helpers-2.1.9 lib/eco/api/policies.rb