Module: ConfigVolumizer

Defined in:
lib/config_volumizer.rb,
lib/config_volumizer/parser.rb,
lib/config_volumizer/version.rb,
lib/config_volumizer/generator.rb

Defined Under Namespace

Modules: Generator, Parser

Constant Summary collapse

VERSION =
"0.3.1"

Class Method Summary collapse

Class Method Details

.fetch(source, mapping_key, mapping_info, default = nil, &block) ⇒ Object

Fetches the data described by the mapping from the source works similar to #parse, but has a default value mechanism and skips the root key

Parameters:

  • source (Hash)
  • mapping_key (String)
  • mapping_info (Object)
  • default (Object) (defaults to: nil)
    • default value if key not found
  • block (proc)
    • default value proc (is passed key as parameter)

Returns:

  • (Object)


30
31
32
33
# File 'lib/config_volumizer.rb', line 30

def fetch(source, mapping_key, mapping_info, default=nil, &block)
  value = Parser.parse(source, mapping_key => mapping_info)
  value.fetch(mapping_key, *[default].compact, &block)
end

.generate(data) ⇒ Hash

Generates a flattened config out of a data hash

Parameters:

  • data (Hash)

Returns:

  • (Hash)

See Also:



41
42
43
# File 'lib/config_volumizer.rb', line 41

def generate(data)
  Generator.generate(data)
end

.parse(source, mapping) ⇒ Hash

Parses keys within the source hash matching base_name returning a hash with all the matched data under a string key matching the base_name

Parameters:

  • source (Hash)
  • mapping (Hash)

Returns:

  • (Hash)

See Also:



16
17
18
# File 'lib/config_volumizer.rb', line 16

def parse(source, mapping)
  Parser.parse(source, mapping)
end