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.ports = [8080, 9090]
p.timeout = 10
p.log = 'api.log'
p.readiness = [{ kind: 'http', port: 8080, path: '/example/readyz' }]
end
end
File-based configuration
Nonnative.configure do |config|
config.load_file('features/configs/processes.yml')
end
Instance Attribute Summary collapse
-
#log ⇒ String?
Path to the Nonnative log file.
-
#name ⇒ String?
Logical system name (used for observability endpoints).
-
#processes ⇒ Array<Nonnative::ConfigurationProcess>
Configured processes.
-
#servers ⇒ Array<Nonnative::ConfigurationServer>
Configured in-process servers.
-
#services ⇒ Array<Nonnative::ConfigurationService>
Configured external dependencies.
-
#url ⇒ String?
Base URL for observability queries (for example
"http://127.0.0.1:8080"). -
#version ⇒ String?
Configuration version.
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.
39 40 41 42 43 |
# File 'lib/nonnative/configuration.rb', line 39 def initialize @processes = [] @servers = [] @services = [] end |
Instance Attribute Details
#log ⇒ String?
Returns path to the Nonnative log file.
55 56 57 |
# File 'lib/nonnative/configuration.rb', line 55 def log @log end |
#name ⇒ String?
Returns logical system name (used for observability endpoints).
46 47 48 |
# File 'lib/nonnative/configuration.rb', line 46 def name @name end |
#processes ⇒ Array<Nonnative::ConfigurationProcess>
Returns configured processes.
58 59 60 |
# File 'lib/nonnative/configuration.rb', line 58 def processes @processes end |
#servers ⇒ Array<Nonnative::ConfigurationServer>
Returns configured in-process servers.
61 62 63 |
# File 'lib/nonnative/configuration.rb', line 61 def servers @servers end |
#services ⇒ Array<Nonnative::ConfigurationService>
Returns configured external dependencies.
64 65 66 |
# File 'lib/nonnative/configuration.rb', line 64 def services @services end |
#url ⇒ String?
Returns base URL for observability queries (for example "http://127.0.0.1:8080").
52 53 54 |
# File 'lib/nonnative/configuration.rb', line 52 def url @url end |
#version ⇒ String?
Returns configuration version.
49 50 51 |
# File 'lib/nonnative/configuration.rb', line 49 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 safe YAML parsing. ERB and environment placeholders are not evaluated, arbitrary object deserialization is not allowed, and unknown structural keys may be ignored. Top-level supported attributes are copied onto this object, and runner sections are transformed into configuration runner objects.
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/nonnative/configuration.rb', line 75 def load_file(path) cfg = Nonnative::ConfigurationFile.load(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.
92 93 94 95 96 97 |
# File 'lib/nonnative/configuration.rb', line 92 def process process = Nonnative::ConfigurationProcess.new yield process processes << process end |
#process_by_name(name) ⇒ Nonnative::ConfigurationProcess
Finds a configured process by name.
129 130 131 132 133 134 |
# File 'lib/nonnative/configuration.rb', line 129 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.
103 104 105 106 107 108 |
# File 'lib/nonnative/configuration.rb', line 103 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" represents an externally managed dependency. It does not manage a Ruby thread or OS process, but it can wait for TCP readiness and optionally control a proxy for the dependency.
117 118 119 120 121 122 |
# File 'lib/nonnative/configuration.rb', line 117 def service service = Nonnative::ConfigurationService.new yield service services << service end |