Class: Kinetic::Configuration

Inherits:
Confstruct::Configuration
  • Object
show all
Defined in:
lib/kinetic/configuration.rb

Overview

Configuration can be set either by passing the set method and or by using the config_file method.

Accessing configuration values by their method accessors will raise Errors::MissingConfigurationValue error. This can be used to ensure that specific values are set at runtime. To access a value without raising an exception use the hash key instead.

Examples:

require 'kinetic'

config_file 'config.yml' # loads the values in config_file into configuration
set :host,  'localhost'  # sets config.host to 'localhost'
config.host   # raises an error if the config host value is not set
config[:host] # returns nil if the host value is not set

Constant Summary collapse

DEFAULTS =

Default configuration values.

{
  name:       File.basename($0),         # name of the application. This also translates to the name of the AMQP exchange
  root:       File.dirname($0),          # the application root directory
  app_file:   $0,                        # the application file
  workers:    1,                         # the number of worker processes to run
  log_file:   'kinetic.log',             # the path of the log file to be used
  host:       'localhost',               # the AMQP host
  port:       5672,                      # the AMQP port
  serializer: :JSON,                     # the message serializer to use
  timeout:    1,                         # the time (in seconds) to wait for various operations
  pid:        "#{File.basename($0)}.pid" # the process pid file
}

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



36
37
38
39
# File 'lib/kinetic/configuration.rb', line 36

def initialize
  super
  self.deep_merge!(DEFAULTS)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)



44
45
46
47
48
# File 'lib/kinetic/configuration.rb', line 44

def method_missing(meth, *args, &block)
  value = super
  raise Kinetic::Errors::MissingConfigurationValue.new("Configuration is missing value for #{meth}") unless value
  value
end