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.



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

#facetObject (readonly)

Returns the value of attribute facet.



117
118
119
# File 'lib/async/service/environment.rb', line 117

def facet
  @facet
end

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

.buildObject

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

#evaluatorObject

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.

Returns:

  • (Boolean)


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_hObject

Convert the environment to a hash.



232
233
234
# File 'lib/async/service/environment.rb', line 232

def to_h
	evaluator.to_h
end

#withObject

Create a new environment with additional configuration.



132
133
134
# File 'lib/async/service/environment.rb', line 132

def with(...)
	return self.class.new(Builder.for(...), self)
end