rails-settings-cached 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -87,18 +87,28 @@ Setting.all('preferences.')
87
87
  ```
88
88
 
89
89
  Set defaults for certain settings of your app. This will cause the defined settings to return with the
90
- Specified value even if they are not in the database. Make a new file in `config/initializers/default_settings.rb`
90
+ Specified value even if they are **not in the database**. Make a new file in `config/initializers/default_settings.rb`
91
91
  with the following:
92
92
 
93
93
  ```ruby
94
94
  Setting.defaults[:some_setting] = 'footastic'
95
+ Setting.where(:var => "some_setting").count
96
+ => 0
97
+ Setting.some_setting
98
+ => "footastic"
95
99
  ```
96
-
97
- Now even if the database is completely empty, you app will have some intelligent defaults:
100
+
101
+ Init defualt value in database, this has indifferent with `Setting.defaults[:some_setting]`, this will **save the value into database**:
98
102
 
99
103
  ```ruby
100
- Setting.some_setting # returns 'footastic'
104
+ Setting.save_default(:some_key) = "123"
105
+ Setting.where(:var => "some_key").count
106
+ => 1
107
+ Setting.some_key
108
+ => "123"
101
109
  ```
110
+
111
+
102
112
 
103
113
  Settings may be bound to any existing ActiveRecord object. Define this association like this:
104
114
  Notice! is not do caching in this version.
@@ -1,2 +1,3 @@
1
1
  class <%= class_name %> < RailsSettings::CachedSettings
2
+ attr_accessible :var
2
3
  end
@@ -15,5 +15,11 @@ module RailsSettings
15
15
  }
16
16
  obj || @@defaults[var_name.to_s]
17
17
  end
18
+
19
+ def self.save_default(key,value)
20
+ if self.send(key) == nil
21
+ self.send("#{key}=",value)
22
+ end
23
+ end
18
24
  end
19
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-settings-cached
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -16,7 +16,7 @@ date: 2012-11-26 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails
19
- requirement: &70170716794980 !ruby/object:Gem::Requirement
19
+ requirement: &70117799454600 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - ! '>='
@@ -24,7 +24,7 @@ dependencies:
24
24
  version: 3.0.0
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70170716794980
27
+ version_requirements: *70117799454600
28
28
  description:
29
29
  email: huacnlee@gmail.com
30
30
  executables: []