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.0.36 lib/eco/api/policies.rb
eco-helpers-2.0.35 lib/eco/api/policies.rb
eco-helpers-2.0.34 lib/eco/api/policies.rb
eco-helpers-2.0.33 lib/eco/api/policies.rb
eco-helpers-2.0.32 lib/eco/api/policies.rb
eco-helpers-2.0.31 lib/eco/api/policies.rb
eco-helpers-2.0.30 lib/eco/api/policies.rb
eco-helpers-2.0.29 lib/eco/api/policies.rb
eco-helpers-2.0.28 lib/eco/api/policies.rb
eco-helpers-2.0.27 lib/eco/api/policies.rb
eco-helpers-2.0.26 lib/eco/api/policies.rb
eco-helpers-2.0.25 lib/eco/api/policies.rb
eco-helpers-2.0.24 lib/eco/api/policies.rb
eco-helpers-2.0.23 lib/eco/api/policies.rb
eco-helpers-2.0.22 lib/eco/api/policies.rb
eco-helpers-2.0.21 lib/eco/api/policies.rb
eco-helpers-2.0.19 lib/eco/api/policies.rb
eco-helpers-2.0.18 lib/eco/api/policies.rb
eco-helpers-2.0.17 lib/eco/api/policies.rb
eco-helpers-2.0.16 lib/eco/api/policies.rb