Module: BeanStalk::Worker::Config

Extended by:
Mixlib::Config
Defined in:
lib/beanstalk-worker/config.rb

Class Method Summary collapse

Class Method Details

.base_merge!Object

Support merging via coercion to symbols.

Parameters:

  • hash (Hash)

    The configuration hash to symbolize and merge.



22
# File 'lib/beanstalk-worker/config.rb', line 22

alias :base_merge! :merge!

.beanstalk_uriString

Helper method for generation the beanstalk uri

Returns:

  • (String)

    The beanstalk uri.



88
89
90
# File 'lib/beanstalk-worker/config.rb', line 88

def self.beanstalk_uri
  [self[:beanstalk][:server], self[:beanstalk][:port]].join(":")
end

.from_file(filename, opts = {}) ⇒ Object

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

Parameters:

  • filename (String)

    The filename to read.

  • opts (Hash) (defaults to: {})

    The options to send

Raises:

  • (IOError)

    Any IO Exceptions that occur.



34
35
36
37
38
# 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) ⇒ Object

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

Parameters:

  • filename (String)

    The file to read.

Raises:

  • (IOError)

    Any IO Exceptions that occur.

  • (Yajl::ParseError)

    Raises Yajl Parsing error on improper json.



69
70
71
# 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) ⇒ Object

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

Parameters:

  • filename (String)

    The file to read.

Raises:

  • (IOError)

    Any IO Exceptions that occur.



46
47
48
# 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) ⇒ Object

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

Parameters:

  • filename (String)

    The file to read.

  • environment (String)

    The environment to use.

Raises:

  • (IOError)

    Any IO Exceptions that occur.

  • (Yajl::ParseError)

    Raises Yajl Parsing error on improper json.



58
59
60
# 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) ⇒ Object

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

Parameters:

  • input (String)

    The json configuration input.

Raises:

  • (IOError)

    Any IO Exceptions that occur.

  • (Yajl::ParseError)

    Raises Yajl Parsing error on improper json.



80
81
82
83
# 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

.inspectObject

Return the configuration itself upon inspection.



12
13
14
# File 'lib/beanstalk-worker/config.rb', line 12

def self.inspect
  configuration.inspect
end

.merge!(hash) ⇒ Object



23
24
25
# File 'lib/beanstalk-worker/config.rb', line 23

def merge!(hash)
  base_merge!(configuration.deep_merge(hash.deep_symbolize_keys))
end