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.1.8 lib/eco/api/policies.rb
eco-helpers-2.1.7 lib/eco/api/policies.rb
eco-helpers-2.1.6 lib/eco/api/policies.rb
eco-helpers-2.1.5 lib/eco/api/policies.rb
eco-helpers-2.1.4 lib/eco/api/policies.rb
eco-helpers-2.1.3 lib/eco/api/policies.rb
eco-helpers-2.1.2 lib/eco/api/policies.rb
eco-helpers-2.1.1 lib/eco/api/policies.rb
eco-helpers-2.0.68 lib/eco/api/policies.rb
eco-helpers-2.0.67 lib/eco/api/policies.rb
eco-helpers-2.0.66 lib/eco/api/policies.rb
eco-helpers-2.0.65 lib/eco/api/policies.rb
eco-helpers-2.0.64 lib/eco/api/policies.rb
eco-helpers-2.0.63 lib/eco/api/policies.rb
eco-helpers-2.0.62 lib/eco/api/policies.rb
eco-helpers-2.0.61 lib/eco/api/policies.rb
eco-helpers-2.0.60 lib/eco/api/policies.rb
eco-helpers-2.0.59 lib/eco/api/policies.rb
eco-helpers-2.0.58 lib/eco/api/policies.rb
eco-helpers-2.0.57 lib/eco/api/policies.rb