customizable_configuration

customizable_configuration is a lib that provides agile way to work with configuration, which can be useful for object initialization


License
MIT
Install
gem install customizable_configuration -v 0.5.0

Documentation

configurates

DESCRIPTION

customizable_configuration is a lib that provides agile way to work with configuration, which can be useful for object initialization.

Travis CI

https://travis-ci.org/Medvedu/customizable_configuration

SAMPLES

SAMPLE 1. BASICS

conf = Settings::Config.create do
  merge_storage Settings::Yaml.load('../configs/first.yml')
end

# Two ways to get an attribute:
puts conf['string'] # => 4
puts conf.string    # => 4

# Any marchalized class is a valid data:
puts conf.sample.dd.to_s # => 2016-09-05 05:42:35 +0300

# Nested hash determitated as sub-storage
puts conf.sample # => {:nodes=>[:cc],
#                      :variables=>{:aa=>15,
#                                   :bb=>[false, true],
#                                   :dd=>2016-09-05 05:42:35 +0300} }

# Access by [] to predicate
puts conf[42].root? # => false

SAMPLE 2. Tricks

## PART 1 CASE-SENSIVITY

# Warning! Keys are case-sensivity. It means that 'config' and 'Config' are
# two different keys

yaml = Settings::Config.create do
  merge_storage Settings::Yaml.load('../configs/second.yml')
end

puts yaml.config # => {:nodes=>[], :variables=>{:param1=>"config/param1",
#                                               :param2=>false, :param3=>[]}}

puts yaml.Config # => {:nodes=>[:param3], :variables=>{:param1=>"Config/param1",
#                                                      :param2=>[true]}}

## PART 2 ROOT

# Sometimes can be useful to load only a part of hash from file, so you can
# use root parameter for merge_storage method:

file = Settings::Yaml.load('../configs/second.yml')

# You can load only YAML part (root: 'config')
part1   = Settings::Config.create { merge_storage file, root: 'config' }
puts part1.param1 # => config/param1

# Or load even more deeper (root: 'Config/param3')
part2 = Settings::Config.create { merge_storage file, root: 'Config/param3' }
print part2.super_deep_array # => [1, 2, 3, 4]

SAMPLE 3. PROVIDERS

## PART 1 ENV

dynamic = Settings::Config.create do
  merge_storage Settings::ENV.load( RbConfig::CONFIG )
end

puts dynamic["RUBY_VERSION_NAME"] # => ruby-2.3.0

## PART 2 YAML

yaml = Settings::Config.create do
  merge_storage Settings::Yaml.load('../configs/second.yml')
end

puts yaml[:config][:param1] # => config/param1

dependencies

Ruby 2.0.0 or higher

License


MIT, see LICENSE