rails-settings-cached 0.4.3 → 0.4.4

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
2
  SHA1:
3
- metadata.gz: 80bfa0c52c2d8fe8b4535ff364b0d727476f9e5c
4
- data.tar.gz: ca264291977f18ee792e52191e6415974263ca13
3
+ metadata.gz: 7fba2dd4d13c0c1a77876382d0207c0815a75d34
4
+ data.tar.gz: b1ccc3d46ba88211fd29952b0eabf020cef3acab
5
5
  SHA512:
6
- metadata.gz: 88de4555fb37729d39d6f1f2f6868fac66399662c2d0139bb59783e07760cd6ca225c45ad2e1d42b10095be5bf8dbe6e356f2961347805ef7394045ce145ac3f
7
- data.tar.gz: 4bdbfc25e039ac4b95baad02f27002a81710cd5ad0378b95f18ccab8583edeef080daba0697f149240c646783c9292ebdc98f5064093078e1587669d5875984a
6
+ metadata.gz: a0342009a9dc86b0f531583cb3de8137944641e8d667acb486b739f7b4bbb4bb611dd33511c7ef41fc6a77a72ea7b842d20f79ee8f3f915d7e9bc03d3c4d618e
7
+ data.tar.gz: 54a0558fee9b43f595801fbe84c40e6907ddc226eeeedbeed458dc466cf2bea35532d6603728cc4e6222948d68528cdc3dee46c26c5cf1dde0f43dca773585ad
@@ -1,6 +1,6 @@
1
1
  require_relative 'rails-settings/settings'
2
- require_relative 'rails-settings/scoped_settings'
3
2
  require_relative 'rails-settings/cached_settings'
3
+ require_relative 'rails-settings/scoped_settings'
4
4
  require_relative 'rails-settings/extend'
5
5
 
6
6
  class RailsSettings::Railtie < Rails::Railtie
@@ -1,17 +1,26 @@
1
1
  module RailsSettings
2
2
  class CachedSettings < Settings
3
3
  def rewrite_cache
4
- Rails.cache.write("rails_settings_cached:#{var}", value)
4
+ Rails.cache.write(cache_key, value)
5
5
  end
6
6
 
7
7
  def expire_cache
8
- Rails.cache.delete("rails_settings_cached:#{var}")
8
+ Rails.cache.delete(cache_key)
9
+ end
10
+
11
+ def cache_key
12
+ self.class.cache_key(var, thing)
9
13
  end
10
14
 
11
15
  class << self
16
+ def cache_key(var_name, scope_object)
17
+ scope = "rails_settings_cached:"
18
+ scope << "#{scope_object.class.base_class.to_s}-#{scope_object.id}:" if scope_object
19
+ scope << "#{var_name}"
20
+ end
21
+
12
22
  def [](var_name)
13
- cache_key = "rails_settings_cached:#{var_name}"
14
- obj = Rails.cache.read(cache_key)
23
+ obj = Rails.cache.read(cache_key(var_name, @object))
15
24
  obj = super(var_name) if obj.nil?
16
25
 
17
26
  return @@defaults[var_name.to_s] if obj.nil?
@@ -1,5 +1,5 @@
1
1
  module RailsSettings
2
- class ScopedSettings < Settings
2
+ class ScopedSettings < CachedSettings
3
3
  def self.for_thing(object)
4
4
  @object = object
5
5
  self
@@ -7,6 +7,8 @@ module RailsSettings
7
7
  cattr_accessor :defaults
8
8
  @@defaults = {}.with_indifferent_access
9
9
 
10
+ belongs_to :thing, polymorphic: true
11
+
10
12
  # Support old plugin
11
13
  if defined?(SettingsDefaults::DEFAULTS)
12
14
  @@defaults = SettingsDefaults::DEFAULTS.with_indifferent_access
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.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Squeegy
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-09-10 00:00:00.000000000 Z
14
+ date: 2015-09-14 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails