README.md in rails-settings-cached-0.3.1 vs README.md in rails-settings-cached-0.3.2
- old
+ new
@@ -7,19 +7,20 @@
to hard code into your rails app. You can store any kind of object. Strings, numbers,
arrays, or any object. Ported to Rails 3!
## Status
-[![CI Status](https://secure.travis-ci.org/huacnlee/rails-settings-cached.png)](http://travis-ci.org/huacnlee/rails-settings-cached)
+- [![Gem Version](https://badge.fury.io/rb/rails-settings-cached.png)](https://rubygems.org/gems/rails-settings-cached)
+- [![CI Status](https://api.travis-ci.org/huacnlee/rails-settings-cached.png)](http://travis-ci.org/huacnlee/rails-settings-cached)
## Setup
Edit your Gemfile:
```ruby
# Rails 4+
-gem "rails-settings-cached", "0.3.0"
+gem "rails-settings-cached", "0.3.1"
# Rails 3.x
gem "rails-settings-cached", "0.2.4"
```
Generate your settings:
@@ -35,11 +36,11 @@
...
end
```
Now just put that migration in the database with:
-
+
```bash
rake db:migrate
```
## Usage
@@ -81,21 +82,21 @@
```
Want a list of all the settings?
```ruby
-Setting.all
-# returns {'admin_password' => 'super_secret', 'date_format' => '%m %d, %Y'}
+Setting.all
+# returns {'admin_password' => 'super_secret', 'date_format' => '%m %d, %Y'}
```
You need name spaces and want a list of settings for a give name space? Just choose your prefered named space delimiter and use Setting.all like this:
```ruby
Setting['preferences.color'] = :blue
Setting['preferences.size'] = :large
Setting['license.key'] = 'ABC-DEF'
-Setting.all('preferences.')
+Setting.all('preferences.')
# returns { 'preferences.color' => :blue, 'preferences.size' => :large }
```
Set defaults for certain settings of your app. This will cause the defined settings to return with the
Specified value even if they are **not in the database**. Make a new file in `config/initializers/default_settings.rb`
@@ -103,32 +104,30 @@
```ruby
Setting.defaults[:some_setting] = 'footastic'
Setting.where(:var => "some_setting").count
=> 0
-Setting.some_setting
+Setting.some_setting
=> "footastic"
```
Init defualt value in database, this has indifferent with `Setting.defaults[:some_setting]`, this will **save the value into database**:
```ruby
Setting.save_default(:some_key, "123")
Setting.where(:var => "some_key").count
=> 1
-Setting.some_key
+Setting.some_key
=> "123"
```
-
-
Settings may be bound to any existing ActiveRecord object. Define this association like this:
Notice! is not do caching in this version.
-
+
```ruby
class User < ActiveRecord::Base
- include RailsSettings::Extend
+ include RailsSettings::Extend
end
```
Then you can set/get a setting for a given user instance just by doing this:
@@ -140,19 +139,19 @@
```
I you want to find users having or not having some settings, there are named scopes for this:
```ruby
-User.with_settings
+User.with_settings
# => returns a scope of users having any setting
-User.with_settings_for('color')
+User.with_settings_for('color')
# => returns a scope of users having a 'color' setting
-User.without_settings
+User.without_settings
# returns a scope of users having no setting at all (means user.settings.all == {})
-User.without_settings('color')
+User.without_settings('color')
# returns a scope of users having no 'color' setting (means user.settings.color == nil)
```
That's all there is to it! Enjoy!