module BeanStalk::Worker::Config

Public Class Methods

base_merge!(hash)

Support merging via coercion to symbols.

@param [ Hash ] hash The configuration hash to symbolize and merge.

Alias for: merge!
beanstalk_uri() click to toggle source

Helper method for generation the beanstalk uri

@return [ String ] The beanstalk uri.

# File lib/beanstalk-worker/config.rb, line 88
def self.beanstalk_uri
  [self[:beanstalk][:server], self[:beanstalk][:port]].join(":")
end
from_file(filename, opts={}) click to toggle source

Loads a given file and passes it to the appropriate parser.

@raise [ IOError ] Any IO Exceptions that occur.

@param [ String ] filename The filename to read. @param [ Hash ] opts The options to send

# File lib/beanstalk-worker/config.rb, line 34
def self.from_file(filename, opts={})
  opts = { :parser => "yaml" }.merge(opts)
  send("from_file_#{opts[:parser]}".to_sym, filename,
    (opts[:environment] || self[:environment]))
end
from_file_json(filename, *args) click to toggle source

Loads a given json file and merges the current context configuration with the updated hash.

@raise [ IOError ] Any IO Exceptions that occur. @raise [ Yajl::ParseError ] Raises Yajl Parsing error on improper json.

@param [ String ] filename The file to read.

# File lib/beanstalk-worker/config.rb, line 69
def self.from_file_json(filename, *args)
  self.from_stream_json(IO.read(filename))
end
from_file_ruby(filename, *args) click to toggle source

Loads a given ruby file and runs instance_eval against it in the context of the current object.

@raise [ IOError ] Any IO Exceptions that occur.

@param [ String ] filename The file to read.

# File lib/beanstalk-worker/config.rb, line 46
def self.from_file_ruby(filename, *args)
  self.instance_eval(IO.read(filename), filename, 1)
end
from_file_yaml(filename, environment) click to toggle source

Loads a given yaml file and merges the current context configuration with the updated hash.

@raise [ IOError ] Any IO Exceptions that occur. @raise [ Yajl::ParseError ] Raises Yajl Parsing error on improper json.

@param [ String ] filename The file to read. @param [ String ] environment The environment to use.

# File lib/beanstalk-worker/config.rb, line 58
def self.from_file_yaml(filename, environment)
  merge!(YAML.load_file(filename).deep_symbolize_keys[environment])
end
from_stream_json(input, *args) click to toggle source

Loads a given json input and merges the current context configuration with the updated hash.

@raise [ IOError ] Any IO Exceptions that occur. @raise [ Yajl::ParseError ] Raises Yajl Parsing error on improper json.

@param [ String ] input The json configuration input.

# File lib/beanstalk-worker/config.rb, line 80
def self.from_stream_json(input, *args)
  parser = Yajl::Parser.new(:symbolize_keys => true)
  merge!(parser.parse(input))
end
inspect() click to toggle source

Return the configuration itself upon inspection.

# File lib/beanstalk-worker/config.rb, line 12
def self.inspect
  configuration.inspect
end
merge!(hash) click to toggle source
# File lib/beanstalk-worker/config.rb, line 23
def merge!(hash)
  base_merge!(configuration.deep_merge(hash.deep_symbolize_keys))
end
Also aliased as: base_merge!