Project

prefered

0.0
No commit activity in last 3 years
No release in over 3 years
Allows you to add preferences to any active record model
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 3.0.0
 Project Readme

Prefered¶ ↑

Prefered allows you to add preferences / settings to any model that extends ActiveRecord::Base in a Rails 3 project

Installation¶ ↑

Gem¶ ↑

You can let bundler to install Prefered by adding this line to your application’s Gemfile:

gem 'prefered'

And then execute:

bundle install

Or install it yourself as:

gem install prefered

DB¶ ↑

Next you will need to run the generator which will create the db migration for you:

rails g prefered:preferences_migration

Then migrate your db:

rake db:migrate

Usage¶ ↑

Now your all installed you can add preferences to your active record model, for instance for a User model:

class User < ActiveRecord::Base
  has_preferences do
    preference :colour, :default => 'green'
    group :email
      preference :html, :default => false
    end
  end
end

This would add the following to your user model:

user.preferences.colour #=> 'green'
user.preferences.email.html #=> false

To change preferences you simply use a setter for each preference:

user.preferences.colour= 'yellow'
user.preferences.email.html= false

And to persist them just save the user model:

user.save

Thanks¶ ↑

Thanks to anyone who gives this a try, peace & love, Rob :)

License¶ ↑

Copyright © 2010 Robert Oles

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.