class Loader
The domain specific language for loading configuration files.
Definitions
def initialize(configuration, root = nil)
Initialize the loader, attached to a specific configuration instance. Any environments generated by the loader will be added to the configuration.
Signature
-
parameter
configuration
Configuration
-
parameter
root
String
The file-system root path for relative path computations.
Implementation
def initialize(configuration, root = nil)
@configuration = configuration
@root = root
end
attr :root
The file-system root path which is injected into the environments as required.
Signature
-
attribute
String
def self.load_file(configuration, path)
Load the specified file into the given configuration.
Signature
-
parameter
configuration
Configuration
Implementation
def self.load_file(configuration, path)
realpath = ::File.realpath(path)
root = ::File.dirname(realpath)
loader = self.new(configuration, root)
if ::Module.method_defined?(:set_temporary_name)
loader.singleton_class.set_temporary_name("#{self}[#{path.inspect}]")
end
loader.instance_eval(File.read(path), path)
end
def environment(**initial, &block)
Create an environment.
Implementation
def environment(**initial, &block)
Environment.build(**initial, &block)
end
def service(name = nil, **options, &block)
Define a service with the specified name.
Adds root
and name
keys.
Signature
-
parameter
name
String
The name of the environment, usually a hostname.
Implementation
def service(name = nil, **options, &block)
options[:name] = name
options[:root] ||= @root
@configuration.add(self.environment(**options, &block))
end