Class: Nonnative::Configuration
- Inherits:
-
Object
- Object
- Nonnative::Configuration
- Defined in:
- lib/nonnative/configuration.rb
Overview
The gem configuration object.
You can populate configuration either programmatically via the DSL (#process, #server, #service), or by loading a YAML file via #load_file.
The configuration is consumed when start is called.
Programmatic configuration
Nonnative.configure do |config|
config.name = 'example'
config.url = 'http://127.0.0.1:8080'
config.log = 'test.log'
config.process do |p|
p.name = 'api'
p.command = -> { './bin/api' }
p.host = '127.0.0.1'
p.port = 8080
p.timeout = 10
p.log = 'api.log'
end
end
File-based configuration
Nonnative.configure do |config|
config.load_file('features/configs/processes.yml')
end
Instance Attribute Summary collapse
- #log ⇒ String, ...
- #name ⇒ String, ...
- #processes ⇒ String, ...
- #servers ⇒ String, ...
- #services ⇒ String, ...
- #url ⇒ String, ...
- #version ⇒ String, ...
Instance Method Summary collapse
-
#initialize ⇒ void
constructor
Creates an empty configuration.
-
#load_file(path) ⇒ void
Loads a configuration file and appends its runners to this instance.
-
#process {|process| ... } ⇒ void
Adds a process configuration entry.
-
#process_by_name(name) ⇒ Nonnative::ConfigurationProcess
Finds a configured process by name.
-
#server {|server| ... } ⇒ void
Adds a server configuration entry.
-
#service {|service| ... } ⇒ void
Adds a service configuration entry.
Constructor Details
#initialize ⇒ void
Creates an empty configuration.
38 39 40 41 42 |
# File 'lib/nonnative/configuration.rb', line 38 def initialize @processes = [] @servers = [] @services = [] end |
Instance Attribute Details
#log ⇒ String, ...
51 52 53 |
# File 'lib/nonnative/configuration.rb', line 51 def log @log end |
#name ⇒ String, ...
51 52 53 |
# File 'lib/nonnative/configuration.rb', line 51 def name @name end |
#processes ⇒ String, ...
51 52 53 |
# File 'lib/nonnative/configuration.rb', line 51 def processes @processes end |
#servers ⇒ String, ...
51 52 53 |
# File 'lib/nonnative/configuration.rb', line 51 def servers @servers end |
#services ⇒ String, ...
51 52 53 |
# File 'lib/nonnative/configuration.rb', line 51 def services @services end |
#url ⇒ String, ...
51 52 53 |
# File 'lib/nonnative/configuration.rb', line 51 def url @url end |
#version ⇒ String, ...
51 52 53 |
# File 'lib/nonnative/configuration.rb', line 51 def version @version end |
Instance Method Details
#load_file(path) ⇒ void
This method returns an undefined value.
Loads a configuration file and appends its runners to this instance.
The file is loaded using the config gem via Nonnative.configurations. Top-level attributes are copied onto this object, and runner sections are transformed into configuration runner objects.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/nonnative/configuration.rb', line 60 def load_file(path) cfg = Nonnative.configurations(path) self.version = cfg.version self.name = cfg.name self.url = cfg.url self.log = cfg.log add_processes(cfg) add_servers(cfg) add_services(cfg) end |
#process {|process| ... } ⇒ void
This method returns an undefined value.
Adds a process configuration entry.
77 78 79 80 81 82 |
# File 'lib/nonnative/configuration.rb', line 77 def process process = Nonnative::ConfigurationProcess.new yield process processes << process end |
#process_by_name(name) ⇒ Nonnative::ConfigurationProcess
Finds a configured process by name.
114 115 116 117 118 119 |
# File 'lib/nonnative/configuration.rb', line 114 def process_by_name(name) process = processes.find { |s| s.name == name } raise NotFoundError, "Could not find process with name '#{name}'" if process.nil? process end |
#server {|server| ... } ⇒ void
This method returns an undefined value.
Adds a server configuration entry.
88 89 90 91 92 93 |
# File 'lib/nonnative/configuration.rb', line 88 def server server = Nonnative::ConfigurationServer.new yield server servers << server end |
#service {|service| ... } ⇒ void
This method returns an undefined value.
Adds a service configuration entry.
A “service” does not manage a Ruby thread or OS process; it exists so that a proxy can be started and controlled for an external dependency.
102 103 104 105 106 107 |
# File 'lib/nonnative/configuration.rb', line 102 def service service = Nonnative::ConfigurationService.new yield service services << service end |