module Raemon::Configuration

Manages configuration settings and defaults

Constants

DEFAULT_DETACH
DEFAULT_ENVIRONMENT
DEFAULT_INSTRUMENTOR_NAME
DEFAULT_LOG_LEVEL
DEFAULT_MEMORY_LIMIT_IN_MEGABYTES
DEFAULT_NUM_WORKERS
DEFAULT_SERVER_NAME
DEFAULT_TIMEOUT

Attributes

settings[RW]

Public Instance Methods

logger() click to toggle source

@return [logger] The logger used by this library

# File lib/raemon/configuration.rb, line 73
def logger
  @logger ||= setup_logger
end
logger=(logger) click to toggle source

@param [Logger] logger Some logger to use with this library

# File lib/raemon/configuration.rb, line 68
def logger=(logger)
  @logger = logger
end
option(name, options = {}) click to toggle source

Define a configuration option with a default.

@example Define the option.

Config.option(:server_name, default: "Raemon")

@param [Symbol] name The name of the configuration option

@param [Hash] options Extras for the option

@note Copied from Mongoid. Thank you!

@private

# File lib/raemon/configuration.rb, line 38
def option(name, options = {})
  define_method(name) do
    settings.has_key?(name) ? settings[name] : options[:default]
  end

  define_method("#{name}=") { |value| settings[name] = value }
  define_method("#{name}?") { !!send(name) }
end
root() click to toggle source

@return [Pathname] the root path for this application

# File lib/raemon/configuration.rb, line 83
def root
  if @root.nil?
    raise 'Raemon::Config.root must be set'
  else
    Pathname.new(@root).expand_path
  end
end
root=(root) click to toggle source

@param [String] root The root path for this application

# File lib/raemon/configuration.rb, line 78
def root=(root)
  @root = root
end

Private Instance Methods

setup_logger() click to toggle source
# File lib/raemon/configuration.rb, line 93
def setup_logger
  target = detach ? root.join("log/#{env}.log") : STDOUT

  @logger = ::Logger.new(target)
  @logger.formatter = ::Logger::Formatter.new
  @logger
end