class Environment
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.
Nested
Definitions
def self.build(...)
Build a new environment using the builder DSL.
Signature
-
parameter
argumentsArray Arguments passed to Builder.for
-
returns
Environment A new environment instance.
Implementation
def self.build(...)
Environment.new(Builder.for(...))
end
def initialize(facet = ::Module.new, parent = nil)
Initialize a new environment.
Signature
-
parameter
facetModule The facet module containing the configuration methods.
-
parameter
parentEnvironment | Nil The parent environment for inheritance.
Implementation
def initialize(facet = ::Module.new, parent = nil)
unless facet.class == ::Module
raise ArgumentError, "Facet must be a module!"
end
@facet = facet
@parent = parent
end
attr :facet
Signature
-
attribute
Module The facet module.
attr :parent
Signature
-
attribute
Environment | Nil The parent environment, if any.
def included(target)
Include this environment's facet into a target module.
Signature
-
parameter
targetModule The target module to include into.
Implementation
def included(target)
@parent&.included(target)
target.include(@facet)
end
def with(...)
Create a new environment with additional configuration.
Signature
-
parameter
argumentsArray Arguments passed to Environment.build.
-
returns
Environment A new environment with this as parent.
Implementation
def with(...)
return self.class.new(Builder.for(...), self)
end
def implements?(interface)
Check if this environment implements a given interface.
Signature
-
parameter
interfaceModule The interface to check.
-
returns
Boolean True if this environment implements the interface.
Implementation
def implements?(interface)
@facet <= interface
end
def evaluator
Create an evaluator for this environment.
Signature
-
returns
Evaluator A lazy evaluator for this environment.
Implementation
def evaluator
return Evaluator.wrap(self)
end
def to_h
Convert the environment to a hash.
Signature
-
returns
Hash A hash representation of the environment.
Implementation
def to_h
evaluator.to_h
end