0.0
No commit activity in last 3 years
No release in over 3 years
A simple and straightforward settings solution that uses an YAML file
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.1.0
~> 1.8.4
~> 3.12
~> 2.12.0
 Project Readme

rad_settings¶ ↑

A simple and straightforward settings solution that uses an YAML file.

Installation¶ ↑

gem install rad_settings

Usage¶ ↑

1. Define your class¶ ↑

class Settings < RadSettings
  source "#{Rails.root}/config/application.yml"
  namespace Rails.env
  load!
end

or

class Settings < RadSettings
  source File.expand_path(File.dirname(__FILE__) + '/../config/application.yml')
  namespace ENV['RACK_ENV']
  load!
end

2. Create your settings¶ ↑

Notice above we specified an absolute path to our settings file called “application.yml”. This is just a typical YAML file. Also notice above that we specified a namespace for our environment. A namespace is just an optional string that corresponds to a key in the YAML file.

Using a namespace allows us to change our configuration depending on our environment:

# config/application.yml
defaults: &defaults
  cool:
    saweet: nested settings
  neat_setting: 24

development:
  <<: *defaults
  neat_setting: 800

test:
  <<: *defaults

production:
  <<: *defaults

3. Access your settings¶ ↑

>> Rails.env
=> "development"

>> ENV['RACK_ENV']
=> "development"

>> Settings.cool
=> {"saweet"=>"nested settings"}

>> Settings['cool']
=> {"saweet"=>"nested settings"}

>> Settings.cool.saweet
=> "nested settings"

>> Settings.cool['saweet']
=> "nested settings"

>> Settings.neat_setting
=> 800

>> Settings.missing
=> NoMethodError: undefined method `missing' for Settings:Class

Contributing to rad_settings¶ ↑

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet.

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it.

  • Fork the project.

  • Start a feature/bugfix branch.

  • Commit and push until you are happy with your contribution.

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2013 servtag GmbH. See LICENSE.txt for further details.