Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

configurates

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configurates

  • 0.5.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 07 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc