No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.document
.gitignore
.rspec
.rvmrc
Gemfile
Gemfile.lock
LICENSE.txt
README.rdoc
Rakefile
VERSION
rad_settings.gemspec

README.rdoc

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

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