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.
99 100 101 102 103 104 105 106 |
# File 'lib/async/service/environment.rb', line 99 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.
109 110 111 |
# File 'lib/async/service/environment.rb', line 109 def facet @facet end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
112 113 114 |
# File 'lib/async/service/environment.rb', line 112 def parent @parent end |
#The parent environment, if any.(parentenvironment) ⇒ Object (readonly)
112 |
# File 'lib/async/service/environment.rb', line 112 attr :parent |
Class Method Details
.build ⇒ Object
Build a new environment using the builder DSL.
92 93 94 |
# File 'lib/async/service/environment.rb', line 92 def self.build(...) Environment.new(Builder.for(...)) end |
Instance Method Details
#evaluator ⇒ Object
Create an evaluator for this environment.
218 219 220 |
# File 'lib/async/service/environment.rb', line 218 def evaluator return Evaluator.wrap(self) end |
#implements?(interface) ⇒ Boolean
Check if this environment implements a given interface.
131 132 133 |
# File 'lib/async/service/environment.rb', line 131 def implements?(interface) @facet <= interface end |
#included(target) ⇒ Object
Include this environment’s facet into a target module.
116 117 118 119 |
# File 'lib/async/service/environment.rb', line 116 def included(target) @parent&.included(target) target.include(@facet) end |
#The facet module.=(facet) ⇒ Object
109 |
# File 'lib/async/service/environment.rb', line 109 attr :facet |
#to_h ⇒ Object
Convert the environment to a hash.
224 225 226 |
# File 'lib/async/service/environment.rb', line 224 def to_h evaluator.to_h end |
#with ⇒ Object
Create a new environment with additional configuration.
124 125 126 |
# File 'lib/async/service/environment.rb', line 124 def with(...) return self.class.new(Builder.for(...), self) end |