Easily read config into a module from Yaml files
Ruby
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
config
lib
spec
.gitignore
.rspec
Gemfile
LICENSE.txt
README.md
Rakefile
yaml_properties.gemspec

README.md

YamlProperties

If you find yourself often setting app config in yaml files for different environments etc. Then this can be quite useful to simply access those variables.

Examples

YamlProperties.redis_port

Will by default read a value from a YAML file in config/properties.yml

redis_port: 1369

Also can be added to a module or class like

module Shutl
  extend YamlProperties
end

##Override filename like this

module Shutl
  extend YamlProperties
  def self.yaml_file
    ENV['SINATRA_ENV'] == 'development' ? 'config/properties.yml' : 'config/properties_production.yml'
  end
end

##Temporarily override values in e.g. cucumber

#lib/shutl.rb
module Shutl
  extend YamlProperties
end

#features/support/env.rb
After do |scenario|
  Shutl.reset!
end

#features/step_definitions/egg_steps.rb
Given /\AThere are \d+ eggs in a dozen\z/ |dozen|
  Shutl.override_attribute :egg, dozen
end

#Yadayada

gem 'yaml_config'

Usual gem/bundler usage/contribution guidelines