https://github.com/solnic/dm-is-configurable
A DataMapper plugin which adds configuration to resources
https://github.com/solnic/dm-is-configurable
Last synced: 3 months ago
JSON representation
A DataMapper plugin which adds configuration to resources
- Host: GitHub
- URL: https://github.com/solnic/dm-is-configurable
- Owner: solnic
- License: mit
- Created: 2008-10-28T21:25:22.000Z (over 16 years ago)
- Default Branch: master
- Last Pushed: 2009-11-28T14:23:35.000Z (over 15 years ago)
- Last Synced: 2025-01-31T20:41:36.760Z (4 months ago)
- Language: Ruby
- Homepage:
- Size: 93.8 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
- Changelog: History.txt
- License: LICENSE
Awesome Lists containing this project
README
# dm-is-configurable
## Disclaimer
THIS IS A WORK-IN-PROGRESS!
The plugin allows you to add configuration to your models.
## Example usage:
require 'dm-is-configurable'
class Kitteh
include DataMapper::Resourceproperty :id, Serial
property :name, Stringis :configurable, :with => {
:cheezburger_limit => 10,
:be_cute => true
}
end# create configuration options for kittehs
Kitteh.auto_migrate!
Kitteh.setup_configurationcute_one = Kitteh.create(:name => 'Cute Kitteh')
ugly_one = Kitteh.create(:name => 'Ugly Kitteh')# support default values:
puts cute_one.configuration.be_cute? # => true
puts cute_one.configuration[:be_cute] # => true
puts cute_one.configuration[:cheezburger_limit] # => 10# provides convenient configuration writers:
ugly_one.configuration[:be_cute] = false
ugly_one.configuration[:cheezburger_limit] = 100puts ugly_one.configuration.be_cute? # => false
puts ugly_one.configuration[:cheezburger_limit] # => 100# or with a bulk assignment:
ugly_one.configuration = {
:be_cute => true,
:cheezburger_limit => 10
}puts ugly_one.configuration.be_cute? # => true
puts ugly_one.configuration[:cheezburger_limit] # => 10