rails-settings-cached 0.6.6 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 63487ca0f7161c9c7f7e4cb6241bf07551882055
4
- data.tar.gz: 2498ef10d3a2a6d16f5b75ba1444f8ffeab5bf31
2
+ SHA256:
3
+ metadata.gz: ac720065903da7de8fed10d171d0145ddeabb6b7d7f0a1b6c66f7e497c79ddb1
4
+ data.tar.gz: 2b20fdde2d824978ef981935b88faf7e3773469bacaa7520dcbcf59376bf0d76
5
5
  SHA512:
6
- metadata.gz: 67341b519564882fa590bbd1a535a8192095b85ded29646e9ee00e6b29bb9a8985c78d07a3f41fdfef57bb51ae5df9ba07bf51fd198bef5200a8c64c816df85c
7
- data.tar.gz: fcbeaae817222dd48f874ab7b0c09ffca3b79ce19d4265e9ca57018012314a0228cc493d870efd167d957d0a23d5dd47c387dbfe788b733b8ae3b36e4df92e5e
6
+ metadata.gz: eab7e6fb1eb995cf1d4e548812964ca6ac342e47c2792598f3db835b6611c31b13dd89e8d0973cf545799dbfeb8aa5ef5bed307a0559ee82484a37ff4df01ceb
7
+ data.tar.gz: 67139f1e6fea2edc490f43fa7a782a245a1b40b82ece38e4bcb479e18752511f2420131add354a48f5140ebf7130bf1ba8af6349336fa483d6e809625f80a7a6
data/README.md CHANGED
@@ -27,10 +27,25 @@ $ rails g settings:install
27
27
 
28
28
  If you want custom model name:
29
29
 
30
+ ```bash
31
+ $ rails g settings:install
32
+ ```
33
+
34
+ Or use a custom name:
35
+
30
36
  ```bash
31
37
  $ rails g settings:install SiteConfig
32
38
  ```
33
39
 
40
+ You will get `app/models/setting.rb`
41
+
42
+ ```rb
43
+ class Setting < RailsSettings::Base
44
+ source Rails.root.join("config/app.yml")
45
+ # cache_prefix { "v1" }
46
+ end
47
+ ```
48
+
34
49
  Now just put that migration in the database with:
35
50
 
36
51
  ```bash
@@ -178,6 +193,8 @@ Setting.foo -> Check Cache -> Exist - Write Cache -> Return
178
193
 
179
194
  ## Change cache key
180
195
 
196
+ When `config/app.yml` has changed, you may need change the cache prefix to expires caches.
197
+
181
198
  ```ruby
182
199
  class Setting < RailsSettings::Base
183
200
  cache_prefix { 'you-prefix' }
@@ -1,5 +1,7 @@
1
1
  # RailsSettings Model
2
2
  class <%= class_name %> < RailsSettings::Base
3
3
  source Rails.root.join("config/app.yml")
4
- namespace Rails.env
4
+
5
+ # When config/app.yml has changed, you need change this prefix to v2, v3 ... to expires caches
6
+ # cache_prefix { "v1" }
5
7
  end
@@ -1,6 +1,5 @@
1
1
  require_relative 'rails-settings/settings'
2
2
  require_relative 'rails-settings/base'
3
- require_relative 'rails-settings/cached_settings'
4
3
  require_relative 'rails-settings/scoped_settings'
5
4
  require_relative 'rails-settings/default'
6
5
  require_relative 'rails-settings/extend'
@@ -13,18 +13,12 @@ module RailsSettings
13
13
  end
14
14
 
15
15
  class << self
16
- def cache_prefix_by_startup
17
- return @cache_prefix_by_startup if defined? @cache_prefix_by_startup
18
- return '' unless Default.enabled?
19
- @cache_prefix_by_startup = Digest::MD5.hexdigest(Default.instance.to_s)
20
- end
21
-
22
16
  def cache_prefix(&block)
23
17
  @cache_prefix = block
24
18
  end
25
19
 
26
20
  def cache_key(var_name, scope_object)
27
- scope = ['rails_settings_cached', cache_prefix_by_startup]
21
+ scope = ["rails_settings_cached"]
28
22
  scope << @cache_prefix.call if @cache_prefix
29
23
  scope << "#{scope_object.class.name}-#{scope_object.id}" if scope_object
30
24
  scope << var_name.to_s
@@ -45,14 +39,6 @@ module RailsSettings
45
39
  Rails.cache.write(cache_key(var_name, @object), value)
46
40
  value
47
41
  end
48
-
49
- def save_default(key, value)
50
- Kernel.warn 'DEPRECATION WARNING: RailsSettings save_default is deprecated ' \
51
- 'and it will removed in 0.7.0. ' \
52
- 'Please use YAML file for default setting.'
53
- return false unless self[key].nil?
54
- self[key] = value
55
- end
56
42
  end
57
43
  end
58
44
  end
@@ -21,18 +21,12 @@ module RailsSettings
21
21
  # foo.bar.dar Nested fetch value
22
22
  return instance[key] if instance.key?(key)
23
23
  keys = key.to_s.split('.')
24
- val = instance
25
- keys.each do |k|
26
- val = val.fetch(k.to_s, nil)
27
- break if val.nil?
28
- end
29
- val
24
+ instance.dig(*keys)
30
25
  end
31
26
 
32
27
  def instance
33
28
  return @instance if defined? @instance
34
29
  @instance = new
35
- @instance
36
30
  end
37
31
  end
38
32
 
@@ -1,7 +1,7 @@
1
1
  module RailsSettings
2
2
  class << self
3
3
  def version
4
- '0.6.6'
4
+ '0.7.0'
5
5
  end
6
6
  end
7
7
  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.6.6
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-08-01 00:00:00.000000000 Z
14
+ date: 2018-06-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -45,16 +45,16 @@ dependencies:
45
45
  name: rubocop
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - ">="
48
+ - - '='
49
49
  - !ruby/object:Gem::Version
50
- version: '0'
50
+ version: 0.46.0
51
51
  type: :development
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
- - - ">="
55
+ - - '='
56
56
  - !ruby/object:Gem::Version
57
- version: '0'
57
+ version: 0.46.0
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
60
  requirement: !ruby/object:Gem::Requirement
@@ -115,7 +115,6 @@ files:
115
115
  - lib/generators/settings/templates/model.rb
116
116
  - lib/rails-settings-cached.rb
117
117
  - lib/rails-settings/base.rb
118
- - lib/rails-settings/cached_settings.rb
119
118
  - lib/rails-settings/default.rb
120
119
  - lib/rails-settings/extend.rb
121
120
  - lib/rails-settings/railtie.rb
@@ -133,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
132
  requirements:
134
133
  - - ">="
135
134
  - !ruby/object:Gem::Version
136
- version: '2.1'
135
+ version: '2.3'
137
136
  required_rubygems_version: !ruby/object:Gem::Requirement
138
137
  requirements:
139
138
  - - ">="
@@ -141,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
140
  version: '0'
142
141
  requirements: []
143
142
  rubyforge_project:
144
- rubygems_version: 2.6.11
143
+ rubygems_version: 2.7.6
145
144
  signing_key:
146
145
  specification_version: 4
147
146
  summary: Settings plugin for Rails that makes managing a table of global keys.
@@ -1,10 +0,0 @@
1
- module RailsSettings
2
- class CachedSettings < Base
3
- def self.inherited(subclass)
4
- Kernel.warn 'DEPRECATION WARNING: RailsSettings::CachedSettings is deprecated ' \
5
- 'and it will removed in 0.7.0. ' \
6
- 'Please use RailsSettings::Base instead.'
7
- super(subclass)
8
- end
9
- end
10
- end