Class: Eco::API::Policies

Inherits:
UseCases show all
Defined in:
lib/eco/api/policies.rb,
lib/eco/api/policies/policy.rb,
lib/eco/api/policies/default_policies.rb

Overview

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

Direct Known Subclasses

DefaultPolicies

Defined Under Namespace

Classes: DefaultPolicies, Policy

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from UseCases

#case, #defined?, #dup, #each, #empty?, #initialize, #items, #length, #merge, #name?, #names, #types

Methods included from Common::ClassAutoLoader

#_autoload_namespace, #autoload_children, #autoload_class?, #autoload_namespace, #autoload_namespace_ignore, #autoloaded_children, #autoloaded_class, #autoloaded_namespaces, #autoloads_children_of, #known_class!, #known_classes, #new_classes, #unloaded_children

Methods included from Common::ClassHelpers

#class_resolver, #descendants, #descendants?, #inheritable_attrs, #inheritable_class_vars, #inherited, #instance_variable_name, #new_class, #resolve_class, #to_constant

Constructor Details

This class inherits a constructor from Eco::API::UseCases

Instance Attribute Details

#policiesObject (readonly)

Returns the value of attribute policies.



9
10
11
# File 'lib/eco/api/policies.rb', line 9

def policies
  @policies
end

Instance Method Details

#add(policy) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
# File 'lib/eco/api/policies.rb', line 17

def add(policy)
  msg = "Expected Eco::API::Policies::Policy object. Given: #{policy}"
  raise ArgumentError, msg unless policy.is_a?(Eco::API::Policies::Policy)

  super
end

#define(name, type: :transform, &block) ⇒ Object



11
12
13
14
15
# File 'lib/eco/api/policies.rb', line 11

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

#launch(people:, session:, job:, options: {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/eco/api/policies.rb', line 24

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

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