Class: Eaco::DSL::Actor::Designators

Inherits:
Base
  • Object
show all
Defined in:
lib/eaco/dsl/actor/designators.rb

Overview

Designators collector using method_missing.

Parses the following DSL:

actor User do
  designators do
    authenticated from: :class
    user          from: :id
    group         from: :group_ids
  end
end

and looks up within the Designators namespace of the Actor model the concrete implementations of the described designators.

Here the User model is expected to define an User::Designators module and to implement within it a class Authenticated < Eaco::Designator

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#options, #target

Instance Method Summary collapse

Methods inherited from Base

eval, #target_eval

Constructor Details

#initializeDesignators

Sets up the designators registry.



30
31
32
33
34
# File 'lib/eaco/dsl/actor/designators.rb', line 30

def initialize(*)
  super

  @designators = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingClass (private)

Looks up the implementation for the designator of the given name, configures it with the given options and saves it in the designators registry.

Parameters:

  • name (Symbol)
  • options (Hash)

Returns:

  • (Class)

See Also:



61
62
63
# File 'lib/eaco/dsl/actor/designators.rb', line 61

def define_designator(name, options)
  designators[name] = implementation_for(name).configure!(options)
end

Instance Attribute Details

#designatorsHash (readonly) Also known as: result

The parsed designators, keyed by type symbol and with concrete implementations as values.

Returns:

  • (Hash)


42
43
44
# File 'lib/eaco/dsl/actor/designators.rb', line 42

def designators
  @designators
end

Instance Method Details

#containerClass (private)

Looks up the Designators namespace within the Eaco::DSL::Actor‘s class.

Returns:

  • (Class)

Raises:

  • Malformed if the Designators module cannot be found.

See Also:



97
98
99
100
101
102
103
104
105
# File 'lib/eaco/dsl/actor/designators.rb', line 97

def container
  @_container ||= begin
    unless target.const_defined?(:Designators)
      raise Malformed, "Please put designators implementations in #{target}::Designators"
    end

    target.const_get(:Designators)
  end
end

#define_designator(name, options) ⇒ Class (private) Also known as: method_missing

Looks up the implementation for the designator of the given name, configures it with the given options and saves it in the designators registry.

Parameters:

  • name (Symbol)
  • options (Hash)

Returns:

  • (Class)

See Also:



58
59
60
# File 'lib/eaco/dsl/actor/designators.rb', line 58

def define_designator(name, options)
  designators[name] = implementation_for(name).configure!(options)
end

#implementation_for(name) ⇒ Class (private)

Looks up the name designator implementation in the Eaco::DSL::Actor‘s Designators namespace.

Parameters:

  • name (Symbol)

Returns:

  • (Class)

Raises:

  • (Malformed)

    if the implementation class is not found.

See Also:



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/eaco/dsl/actor/designators.rb', line 76

def implementation_for(name)
  impl = name.to_s.camelize.intern

  unless container.const_defined?(impl)
    raise Malformed, "      Implementation \#{container}::\#{impl} for Designator \#{name} not found.\n    EOF\n  end\n\n  container.const_get(impl)\nend\n"