cached_resource 4.0.0 → 4.1.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
2
  SHA1:
3
- metadata.gz: 1da93573faeee91075cb30f90b71dc9e4ac9dec5
4
- data.tar.gz: 884eba1ec80a0184456a1de1e1e966fda965a461
3
+ metadata.gz: e681f36b01cd42d9dc1f81d123715a52761239b8
4
+ data.tar.gz: c0993c173aa2455c4ba9235491fcafc7b06302d7
5
5
  SHA512:
6
- metadata.gz: c2670efa06013b198090f5b62f60daae68f4a9c87b53bfe7cc16be162eea9a26373faa0947e754e5145e513da2717046f549ad65520066de3bfa62225d1400c1
7
- data.tar.gz: c439a57ebe49cd3cb88acbb095c09af729b851659bbde40f72c40d08c323728cc2d123c80a80c8304dc1d3d58e541d96c4d791af04d2c4a15524563d730f2331
6
+ metadata.gz: d89d643a0e8a62872af14be969dd433be66e911e067ae6427e0ed95d2b493c4b97ea04355a78d0707a80f8ec03feadbb9da28c79b7fd5ecf7eca1168c43c2b8b
7
+ data.tar.gz: 67cbb77acac9166d0a83273de0ced52360c96deb0a5e67c5cac52a8925614dcc33a1a09703852efb729f47345b628d27a0cb49881926e8ba726661aeb91f2ada
data/README.md CHANGED
@@ -16,6 +16,7 @@ CachedResource is designed to be framework agnostic, but will hook into Rails fo
16
16
 
17
17
  * 3.2.x
18
18
  * 4.0.0
19
+ * 4.1.x
19
20
 
20
21
  ## Configuration
21
22
  **Set up CachedResource across all ActiveResources:**
@@ -104,6 +105,15 @@ If you need to clear the entire cache just do the following:
104
105
 
105
106
  MyActiveResource.clear_cache
106
107
 
108
+ ---
109
+ Sometimes you might have a case the resource pathing is non-unique per call. This can create a situation where your caching the same result for multiple calls:
110
+
111
+ MyActiveResource.find(:one, from: "/admin/shop.json")
112
+
113
+ Since resources are cached with an argument based key, you may pass in extra data to be appended to the cache key:
114
+
115
+ MyActiveResource.find(:one, from: "/admin/shop.json", uid: "unique value")
116
+
107
117
  ## Testing
108
118
  rake
109
119
 
@@ -5,8 +5,8 @@ require "cached_resource/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "cached_resource"
7
7
  s.version = CachedResource::VERSION
8
- s.authors = "Andrew Chan"
9
- s.email = "email@suspi.net"
8
+ s.authors = "Morgan Brown"
9
+ s.email = "brown.mhg@gmail.com"
10
10
  s.homepage = "http://github.com/Ahsizara/cached_resource"
11
11
  s.summary = %q{Caching for ActiveResource}
12
12
  s.description = %q{Enables request-based caching for ActiveResource}
@@ -85,7 +85,9 @@ module CachedResource
85
85
  def cache_read(key)
86
86
  object = cached_resource.cache.read(key).try do |cache|
87
87
  if cache.is_a? Enumerable
88
- cache.map { |record| full_dup(record) }
88
+ restored = cache.map { |record| full_dup(record) }
89
+ next restored unless respond_to?(:collection_parser)
90
+ collection_parser.new(restored)
89
91
  else
90
92
  full_dup(cache)
91
93
  end
@@ -1,3 +1,3 @@
1
1
  module CachedResource
2
- VERSION = "4.0.0"
2
+ VERSION = "4.1.0"
3
3
  end
@@ -153,6 +153,29 @@ describe CachedResource do
153
153
  result1.should_not be_frozen
154
154
  end
155
155
 
156
+ shared_examples "collection_return_type" do
157
+ if ActiveResource::VERSION::MAJOR >= 4
158
+ it "should return an ActiveResource::Collection" do
159
+ cached = Thing.cached_resource.cache.read("thing/all")
160
+ cached.should be_instance_of(ActiveResource::Collection)
161
+ end
162
+
163
+ it "should return an instance of the collection_parser" do
164
+ Thing.cached_resource.cache.clear
165
+ class CustomCollection < ActiveResource::Collection; end
166
+ Thing.collection_parser = CustomCollection
167
+ Thing.all
168
+ cached = Thing.cached_resource.cache.read("thing/all")
169
+ cached.should be_instance_of(CustomCollection)
170
+ end
171
+ else
172
+ it "should return an Array" do
173
+ cached = Thing.cached_resource.cache.read("thing/all")
174
+ cached.should be_instance_of(Array)
175
+ end
176
+ end
177
+ end
178
+
156
179
  shared_examples "collection_freezing" do
157
180
  it "should not return a frozen collection on first request" do
158
181
  Thing.cached_resource.cache.clear
@@ -221,6 +244,8 @@ describe CachedResource do
221
244
  Thing.all
222
245
  end
223
246
 
247
+ include_examples "collection_return_type"
248
+
224
249
  include_examples "collection_freezing"
225
250
 
226
251
  it "should write cache entries for its members" do
@@ -358,6 +383,8 @@ describe CachedResource do
358
383
  Thing.all
359
384
  end
360
385
 
386
+ include_examples "collection_return_type"
387
+
361
388
  include_examples "collection_freezing"
362
389
 
363
390
  it "should not write cache entries for its members" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cached_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Andrew Chan
7
+ - Morgan Brown
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-01 00:00:00.000000000 Z
11
+ date: 2014-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Enables request-based caching for ActiveResource
84
- email: email@suspi.net
84
+ email: brown.mhg@gmail.com
85
85
  executables: []
86
86
  extensions: []
87
87
  extra_rdoc_files: []