Skip to content

solnic/dm-is-configurable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A DataMapper plugin which adds configuration to resources

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages