easyconf-rails

easyconf-rails makes customizing your Rails application easy. (Surprise!) To use it, follow these simple steps:

1. Add the following line to your project's Gemfile:

gem 'easyconf-rails'

2. Run bundle update.

3. Create a YAML file called defaults.yml in your project's config directory. This file will contain your project's default configuration values. Individual installations SHOULD NOT change this file. For example:

---
should_donate: 10
awesomeness:
  ruby: true
  rspec: true

4. Create a YAML file called config.yml in your project's root directory. These settings will take precedence over the settings in defaults.yml, so you should instruct your users to change their settings here. For example:

---
should_support_easyconf: true
should_donate: 5
donate_to: 1A9hGUYswsMLNdaeH9qMrjoJKQGnYKgmT2
awesomeness:
  easyconf: true
  rails: true
  perl: false
  rspec: false

why_easyconf_is_awesome:
  - its_easiness
  - YAML
  -
    recursive_processing: true

5. Now you're ready to use config in your application.

$config.should_support_easyconf # true
$config.should_donate # 5
$config.awesomeness.easyconf # true
$config.awesomeness.ruby # true
$config.awesomeness.rspec # false
$config.why_easyconf_is_awesome[0] # 'its_easiness'
$config.why_easyconf_is_awesome[2].recursive_processing # true
$config.variable_that_was_never_defined # raises NameError

# You can reload your configuration file by with .reload!.
$config.reload!

BIG RED WARNING

$config is a mutable global variable, and should therefore be treated with extreme caution. In particular, $config.reload! will reset the value of $config in all threads; it is therefore important to ensure that a program's corrent functioning does not rely on subsequent accesses to the $config value to be consistent.

THE WRONG WAY ^^^^^^^^^^^^^

Person[$config.good_guy].kill(Person[$config.bad_guy])

is wrong because $config.reload! could have been called after evaluating the value of Person[$config.good_guy], but before calling its kill() method. If $config.bad_guy was set to the former value of $config.good_guy, we would be asking Person[$config.bad_guy] to kill itself.

THE RIGHT WAY ^^^^^^^^^^^^^

$config.lock do
    Person[config.good_guy].kill(Person[config.bad_guy])
end

is correct because this gaurantees that config.bad_guy and config.good_guy are consistent. Even if they're switched in the interim, no one will ever be asked to kill themselves.