An open API service indexing awesome lists of open source software.

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

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::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