configurable_engine 0.4.6 → 0.4.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6818d2942967d86bf45d1e1c65cb13308baa2895
4
- data.tar.gz: d8980df6e210571c7ed06b799ac4eb61b36986be
3
+ metadata.gz: 42b345dc60ccd203b5e50caa3a5c626d3db7b850
4
+ data.tar.gz: f5cdc2bbefe5017c78db8ccb644da9daa7db638b
5
5
  SHA512:
6
- metadata.gz: 671f136a982caff40684be36d236506fd2621eb2eba35d35f16f3b771a5b00eac9f21967ca2a12d1982bc731c83d06a8c7dbef9dcca2ea7b943c58ccf9498c7d
7
- data.tar.gz: 3c5a422c4cc0ef2304f80f9d8cf7cbf8136075079cdecae88c96a4b3a063e7607043f1a31b27fda6c1b1640b478da8d098fc718341bb23f4e9d6f92126c8e4b3
6
+ metadata.gz: 42b929c5021f20fa1eac5d5499007d077dad5148ab7928d2d2afc1cfdb7088011053c903faa2bba52842c7b4d85584ad175d366f0c64765f9c0d4e25e7c86e61
7
+ data.tar.gz: 943f8e63591d88a8d21d9cd964bea594218999a2513f62027af6da1afb01bb400a862cc5ad05ad777765391b96e4f7aab221beea090b721dc9a56d69fbd25f74
@@ -1,3 +1,7 @@
1
+ ### v0.4.7 - November 4, 2014
2
+ **bug fix**
3
+ Configurable broke for users using cacheing.
4
+
1
5
  ### v0.4.6 - October 28, 2014
2
6
  **cleanup**
3
7
  When using Configurable with cache, destroying a configurable instance erases it from cache
@@ -29,20 +29,40 @@ class Configurable < ActiveRecord::Base
29
29
  end
30
30
  end
31
31
 
32
+ def self.cache_key(key)
33
+ "configurable_engine:#{key}"
34
+ end
35
+
32
36
  def self.[](key)
33
37
  return parse_value key, defaults[key][:default] unless table_exists?
34
38
 
35
- config = if ConfigurableEngine::Engine.config.use_cache
36
- Rails.cache.fetch("configurable_engine:#{key}") {
37
- find_by_name(key)
38
- }
39
- else
40
- find_by_name(key)
39
+ value, found = [false, false]
40
+ database_finder = -> do
41
+ config = find_by_name(key)
42
+ found = !!config
43
+ value = config.try(:value)
41
44
  end
42
45
 
43
- return parse_value key, defaults[key][:default] unless config
44
46
 
45
- config.value
47
+ if ConfigurableEngine::Engine.config.use_cache
48
+ found = Rails.cache.exist?(cache_key(key))
49
+ if found
50
+ value = Rails.cache.fetch(cache_key(key))
51
+ else
52
+ database_finder.call
53
+ if found
54
+ Rails.cache.store cache_key(key), value
55
+ end
56
+ end
57
+ else
58
+ database_finder.call
59
+ end
60
+
61
+ if found
62
+ value
63
+ else
64
+ parse_value key, defaults[key][:default]
65
+ end
46
66
  end
47
67
 
48
68
  def value
@@ -122,6 +142,6 @@ class Configurable < ActiveRecord::Base
122
142
  end
123
143
 
124
144
  def invalidate_cache
125
- Rails.cache.delete("configurable_engine:#{self.name}")
145
+ Rails.cache.delete(Configurable.cache_key self.name)
126
146
  end
127
147
  end
@@ -1,3 +1,3 @@
1
1
  module ConfigurableEngine
2
- VERSION = '0.4.6'
2
+ VERSION = '0.4.7'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configurable_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Campbell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-28 00:00:00.000000000 Z
12
+ date: 2014-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails