Class: Async::Service::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/async/service/configuration.rb

Overview

Manages environments which describes how to host a specific set of services.

Environments are key-value maps with lazy value resolution. An environment can inherit from a parent environment, which can provide defaults

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initialize an empty configuration.



27
28
29
# File 'lib/async/service/configuration.rb', line 27

def initialize
  @environments = []
end

Instance Attribute Details

#environmentsObject (readonly)

Returns the value of attribute environments.



31
32
33
# File 'lib/async/service/configuration.rb', line 31

def environments
  @environments
end

Class Method Details

.load(paths = ARGV) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/async/service/configuration.rb', line 16

def self.load(paths = ARGV)
  configuration = self.new
  
  paths.each do |path|
    configuration.load_file(path)
  end
  
  return configuration
end

Instance Method Details

#add(environment) ⇒ Object

Add the environment to the configuration.



52
53
54
# File 'lib/async/service/configuration.rb', line 52

def add(environment)
  @environments << environment
end

#controller(**options) ⇒ Object



47
48
49
# File 'lib/async/service/configuration.rb', line 47

def controller(**options)
  Controller.new(self.services(**options).to_a)
end

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/async/service/configuration.rb', line 33

def empty?
  @environments.empty?
end

#load_file(path) ⇒ Object

Load the specified configuration file. See Loader#load_file for more details.



57
58
59
# File 'lib/async/service/configuration.rb', line 57

def load_file(path)
  Loader.load_file(self, path)
end

#services(implementing: nil) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/async/service/configuration.rb', line 37

def services(implementing: nil)
  return to_enum(:services, implementing: implementing) unless block_given?
  
  @environments.each do |environment|
    next if implementing and environment.implements?(implementing)
    
    yield Generic.wrap(environment)
  end
end