public
Description: Rails plugin: supports dynamic configuration for any class or model (does not depend on ActiveRecord).
Homepage: http://rpheath.com/posts/357-rails-plugin-acts-as-configurable
Clone URL: git://github.com/rpheath/acts_as_configurable.git
rpheath (author)
Tue Oct 28 05:54:24 -0700 2008
commit  0e5c4440e8dbf03a8a008afe22332387080a2c32
tree    df2b66851e53c2a24a3a763ff84a926a1c20e009
parent  e259ac022230cab41a957a3e29de9c7cd3ae6c41
README.textile

ActsAsConfigurable

Rails plugin that adds dynamic (non-database) configuration to any ActiveRecord model.

Examples

Basic usage:


class User < ActiveRecord::Base
  acts_as_configurable
  
  configuration do |config|
    config.passwords.min_length = 6
    config.passwords.max_length = 12  
  end
end

And then to access that configuration, simply call:


$> User.configuration
$> => {:passwords => { :min_length => 6, :max_length => 12 }}

Or just keep going down the chain to get to the specifics:


$> User.configuration.passwords
$> => {:min_length => 6, :max_length => 12}
$> User.configuration.passwords.min_length
$> => 6

Now, granted that a “configuration” class method is common enough that there may be a case
where you have a conflict. Well, you can also configure that part:


class User < ActiveRecord::Base
  acts_as_configurable :with => :settings
  
  settings do |setting|
    setting.passwords.min_length = 6
    setting.passwords.max_length = 12
  end
end

Then just use “settings” in place of “configuration” when accessing the data.


$> User.settings.passwords
$> => {:min_length => 6, :max_length => 12}

© 2008 Ryan Heath and Chris Scharf, released under the MIT license