-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.txt
51 lines (36 loc) · 1.28 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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::Resource
property :id, Serial
property :name, String
is :configurable, :with => {
:cheezburger_limit => 10,
:be_cute => true
}
end
# create configuration options for kittehs
Kitteh.auto_migrate!
Kitteh.setup_configuration
cute_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] = 100
puts 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