Class: Backdat::Config

Inherits:
Object
  • Object
show all
Extended by:
Mixlib::Config
Defined in:
lib/backdat/config.rb

Overview

The configuration object for backdat.

Class Method Summary collapse

Class Method Details

.from_file(filename, parser = "ruby") ⇒ Object

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

Parameters:

  • filename (String)

    The filename to read.

Raises:

  • (IOError)

    Any IO Exceptions that occur.



19
20
21
# File 'lib/backdat/config.rb', line 19

def self.from_file(filename, parser="ruby")
  send("from_file_#{parser}".to_sym, filename)
end

.from_file_json(filename) ⇒ 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.



40
41
42
# File 'lib/backdat/config.rb', line 40

def self.from_file_json(filename)
  self.from_stream_json(IO.read(filename))
end

.from_file_ruby(filename) ⇒ 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.



29
30
31
# File 'lib/backdat/config.rb', line 29

def self.from_file_ruby(filename)
  self.instance_eval(IO.read(filename), filename, 1)
end

.from_stream_json(input) ⇒ 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.



51
52
53
54
# File 'lib/backdat/config.rb', line 51

def self.from_stream_json(input)
  parser = Yajl::Parser.new(:symbolize_keys => true)
  configuration.merge!(parser.parse(input))
end

.inspectObject

Return the configuration itself upon inspection.



10
11
12
# File 'lib/backdat/config.rb', line 10

def self.inspect
  configuration.inspect
end