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 Language::Klass::AutoLoader

#_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 Language::Klass::Hierarchy

#descendants, #descendants?

Methods included from Language::Klass::Resolver

#class_resolver, #resolve_class

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)


22
23
24
25
26
27
# File 'lib/eco/api/policies.rb', line 22

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

  super
end

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



11
12
13
14
15
16
17
18
19
20
# 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(data:, session:, job:, options: {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/eco/api/policies.rb', line 29

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

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