Class: Async::Service::Environment
- Inherits:
-
Object
- Object
- Async::Service::Environment
- Defined in:
- lib/async/service/environment.rb
Overview
Represents a service configuration with lazy evaluation and module composition.
Environments store configuration as methods that can be overridden and composed using Ruby modules. They support lazy evaluation through evaluators.
Defined Under Namespace
Instance Attribute Summary collapse
-
#facet ⇒ Object
readonly
Returns the value of attribute facet.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
- #The parent environment, if any.(parentenvironment) ⇒ Object readonly
Class Method Summary collapse
-
.build ⇒ Object
Build a new environment using the builder DSL.
Instance Method Summary collapse
-
#evaluator ⇒ Object
Create an evaluator for this environment.
-
#implements?(interface) ⇒ Boolean
Check if this environment implements a given interface.
-
#included(target) ⇒ Object
Include this environment’s facet into a target module.
-
#initialize(facet = ::Module.new, parent = nil) ⇒ Environment
constructor
Initialize a new environment.
- #The facet module.=(facet) ⇒ Object
-
#to_h ⇒ Object
Convert the environment to a hash.
-
#with ⇒ Object
Create a new environment with additional configuration.
Constructor Details
#initialize(facet = ::Module.new, parent = nil) ⇒ Environment
Initialize a new environment.
107 108 109 110 111 112 113 114 |
# File 'lib/async/service/environment.rb', line 107 def initialize(facet = ::Module.new, parent = nil) unless facet.class == ::Module raise ArgumentError, "Facet must be a module!" end @facet = facet @parent = parent end |
Instance Attribute Details
#facet ⇒ Object (readonly)
Returns the value of attribute facet.
117 118 119 |
# File 'lib/async/service/environment.rb', line 117 def facet @facet end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
120 121 122 |
# File 'lib/async/service/environment.rb', line 120 def parent @parent end |
#The parent environment, if any.(parentenvironment) ⇒ Object (readonly)
120 |
# File 'lib/async/service/environment.rb', line 120 attr :parent |
Class Method Details
.build ⇒ Object
Build a new environment using the builder DSL.
100 101 102 |
# File 'lib/async/service/environment.rb', line 100 def self.build(...) Environment.new(Builder.for(...)) end |
Instance Method Details
#evaluator ⇒ Object
Create an evaluator for this environment.
226 227 228 |
# File 'lib/async/service/environment.rb', line 226 def evaluator return Evaluator.wrap(self) end |
#implements?(interface) ⇒ Boolean
Check if this environment implements a given interface.
139 140 141 |
# File 'lib/async/service/environment.rb', line 139 def implements?(interface) @facet <= interface end |
#included(target) ⇒ Object
Include this environment’s facet into a target module.
124 125 126 127 |
# File 'lib/async/service/environment.rb', line 124 def included(target) @parent&.included(target) target.include(@facet) end |
#The facet module.=(facet) ⇒ Object
117 |
# File 'lib/async/service/environment.rb', line 117 attr :facet |
#to_h ⇒ Object
Convert the environment to a hash.
232 233 234 |
# File 'lib/async/service/environment.rb', line 232 def to_h evaluator.to_h end |