rpheath / acts_as_configurable
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
0e5c444
acts_as_configurable / 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
