Class: Async::Service::Loader
- Inherits:
-
Object
- Object
- Async::Service::Loader
- Defined in:
- lib/async/service/loader.rb
Overview
The domain specific language for loading configuration files.
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
The file-system root path which is injected into the environments as required.
Class Method Summary collapse
-
.load_file(configuration, path) ⇒ Object
Load the specified file into the given configuration.
Instance Method Summary collapse
-
#environment(**initial, &block) ⇒ Object
Create an environment.
-
#initialize(configuration, root = nil) ⇒ Loader
constructor
Initialize the loader, attached to a specific configuration instance.
- #load_file(path) ⇒ Object
-
#service(name, &block) ⇒ Object
Define a host with the specified name.
Constructor Details
#initialize(configuration, root = nil) ⇒ Loader
Initialize the loader, attached to a specific configuration instance. Any environments generated by the loader will be added to the configuration.
16 17 18 19 |
# File 'lib/async/service/loader.rb', line 16 def initialize(configuration, root = nil) @configuration = configuration @root = root end |
Instance Attribute Details
#root ⇒ Object (readonly)
The file-system root path which is injected into the environments as required.
23 24 25 |
# File 'lib/async/service/loader.rb', line 23 def root @root end |
Class Method Details
.load_file(configuration, path) ⇒ Object
Load the specified file into the given configuration.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/async/service/loader.rb', line 28 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 |
Instance Method Details
#environment(**initial, &block) ⇒ Object
Create an environment.
46 47 48 |
# File 'lib/async/service/loader.rb', line 46 def environment(**initial, &block) Environment.build(**initial, &block) end |
#load_file(path) ⇒ Object
41 42 43 |
# File 'lib/async/service/loader.rb', line 41 def load_file(path) Loader.load_file(@configuration, File.(path, @root)) end |
#service(name, &block) ⇒ Object
Define a host with the specified name. Adds root and authority keys.
53 54 55 |
# File 'lib/async/service/loader.rb', line 53 def service(name, &block) @configuration.add(self.environment(name: name, root: @root, &block)) end |