module BeanStalk::Worker::Config
Public Class Methods
Support merging via coercion to symbols.
@param [ Hash ] hash The configuration hash to symbolize and merge.
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
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
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
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
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
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
Return the configuration itself upon inspection.
# File lib/beanstalk-worker/config.rb, line 12 def self.inspect configuration.inspect end
# File lib/beanstalk-worker/config.rb, line 23 def merge!(hash) base_merge!(configuration.deep_merge(hash.deep_symbolize_keys)) end