Class: Async::Service::Environment

Inherits:
Object
  • Object
show all
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

Classes: Builder, Evaluator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#facetObject (readonly)

Returns the value of attribute facet.



109
110
111
# File 'lib/async/service/environment.rb', line 109

def facet
  @facet
end

#parentObject (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

.buildObject

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

#evaluatorObject

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.

Returns:

  • (Boolean)


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_hObject

Convert the environment to a hash.



224
225
226
# File 'lib/async/service/environment.rb', line 224

def to_h
  evaluator.to_h
end

#withObject

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