Class: Eaco::DSL::Actor::Designators
- 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
Instance Attribute Summary collapse
-
#designators ⇒ Hash
(also: #result)
readonly
The parsed designators, keyed by type symbol and with concrete implementations as values.
Attributes inherited from Base
Instance Method Summary collapse
-
#container ⇒ Class
private
Looks up the
Designatorsnamespace within the Eaco::DSL::Actor‘s class. -
#define_designator(name, options) ⇒ Class
(also: #method_missing)
private
Looks up the implementation for the designator of the given
name, configures it with the givenoptionsand saves it in the designators registry. -
#implementation_for(name) ⇒ Class
private
Looks up the
namedesignator implementation in the Eaco::DSL::Actor‘sDesignatorsnamespace. -
#initialize ⇒ Designators
constructor
Sets up the designators registry.
Methods inherited from Base
Constructor Details
#initialize ⇒ Designators
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_missing ⇒ Class (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.
61 62 63 |
# File 'lib/eaco/dsl/actor/designators.rb', line 61 def define_designator(name, ) designators[name] = implementation_for(name).configure!() end |
Instance Attribute Details
#designators ⇒ Hash (readonly) Also known as: result
The parsed designators, keyed by type symbol and with concrete implementations as values.
42 43 44 |
# File 'lib/eaco/dsl/actor/designators.rb', line 42 def designators @designators end |
Instance Method Details
#container ⇒ Class (private)
Looks up the Designators namespace within the Eaco::DSL::Actor‘s class.
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.
58 59 60 |
# File 'lib/eaco/dsl/actor/designators.rb', line 58 def define_designator(name, ) designators[name] = implementation_for(name).configure!() end |
#implementation_for(name) ⇒ Class (private)
Looks up the name designator implementation in the Eaco::DSL::Actor‘s Designators namespace.
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" |