Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,83 @@ | ||
# Settings gem for Rails | ||
|
||
Complete rewrite | ||
[![Build Status](https://secure.travis-ci.org/ledermann/rails-settings.png)](http://travis-ci.org/ledermann/rails-settings) | ||
|
||
Handling settings for ActiveRecord objects (with defaults). | ||
|
||
**BEWARE: WORK IN PROGRESS!** | ||
|
||
|
||
## Requirements | ||
|
||
Rails 3.1.x or 3.2.x. | ||
|
||
Tested with Ruby 1.8.7, 1.9.3 and 2.0.0 | ||
|
||
|
||
# Example | ||
|
||
### Define Settings for a model with default values | ||
|
||
```ruby | ||
class User < ActiveRecord::Base | ||
has_settings :dashboard => { :theme => 'blue', :view => 'monthly', :filter => false }, | ||
:calendar => { :scope => 'company'} | ||
end | ||
``` | ||
|
||
Beware: Work in progress! | ||
### Set settings for a given object | ||
|
||
```ruby | ||
user = User.find(1) | ||
user.settings(:dashboard).theme = 'black' | ||
user.settings(:calendar).scope = 'all' | ||
user.settings(:calendar).display = 'daily' | ||
user.save! | ||
``` | ||
|
||
or | ||
|
||
```ruby | ||
user = User.find(1) | ||
user.settings(:dashboard).update_attributes! :theme => 'black' | ||
user.settings(:calendar).update_attributes! :scope => 'all', :display => 'dialy' | ||
``` | ||
|
||
|
||
### Get settings | ||
|
||
```ruby | ||
user = User.find(1) | ||
user.settings(:dashboard).theme | ||
# => 'black | ||
|
||
user.settings(:dashboard).view | ||
# => 'monthly' (it's default) | ||
|
||
user.settings(:calendar).scope | ||
# => 'all' | ||
``` | ||
|
||
|
||
## Installation | ||
|
||
Include the gem in your Gemfile: | ||
|
||
```ruby | ||
gem 'ledermann-rails-settings', :require => 'rails-settings', :branch => 'rewrite' | ||
``` | ||
|
||
Generate and run the migration: | ||
|
||
```shell | ||
rails g rails-settings:migration | ||
rake db:migrate | ||
``` | ||
|
||
|
||
## License | ||
|
||
MIT License | ||
Copyright (c) 2013 Georg Ledermann | ||
|
||
This gem is a complete rewrite of [rails-settings](https://github.com/Squeegy/rails-settings) by [Alex Wayne](https://github.com/Squeegy) |