Class: Nonnative::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializevoid

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

#logString, ...

Returns:



51
52
53
# File 'lib/nonnative/configuration.rb', line 51

def log
  @log
end

#nameString, ...

Returns:



51
52
53
# File 'lib/nonnative/configuration.rb', line 51

def name
  @name
end

#processesString, ...

Returns:



51
52
53
# File 'lib/nonnative/configuration.rb', line 51

def processes
  @processes
end

#serversString, ...

Returns:



51
52
53
# File 'lib/nonnative/configuration.rb', line 51

def servers
  @servers
end

#servicesString, ...

Returns:



51
52
53
# File 'lib/nonnative/configuration.rb', line 51

def services
  @services
end

#urlString, ...

Returns:



51
52
53
# File 'lib/nonnative/configuration.rb', line 51

def url
  @url
end

#versionString, ...

Returns:



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.

Parameters:

  • path (String)

    path to a configuration file (typically YAML)



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.

Yield Parameters:



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.

Parameters:

  • name (String)

Returns:

Raises:



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.

Yield Parameters:



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.

Yield Parameters:



102
103
104
105
106
107
# File 'lib/nonnative/configuration.rb', line 102

def service
  service = Nonnative::ConfigurationService.new
  yield service

  services << service
end