Skip to content

Commit

Permalink
Added some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ledermann committed Mar 4, 2013
1 parent e894e4e commit 90fb93c
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions README.md
@@ -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)

0 comments on commit 90fb93c

Please sign in to comment.