Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A DataMapper plugin which adds configuration to resources

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 tasks
Octocat-spinner-32 History.txt
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Manifest.txt
Octocat-spinner-32 README.markdown
Octocat-spinner-32 README.txt
Octocat-spinner-32 Rakefile
Octocat-spinner-32 TODO
README.markdown

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
Something went wrong with that request. Please try again.