active_remote-cached 0.0.4 → 0.0.5

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: 037ff5730170b6fd9bcde427a2551d17eada4242
4
- data.tar.gz: d7800b6e88135fac587afc65b3f24cd895c6f510
3
+ metadata.gz: d0f5c9001aeadeb02257a3a6cbc8206e0209e3e7
4
+ data.tar.gz: b50ea3df9a27c2cd8f38c47f49687880a67aa8af
5
5
  SHA512:
6
- metadata.gz: c23a65bb8c5f8c3fb4d52402be4bc2ad233a402a041574fa29a3fce657fb9b53a0b48b76dbc4fb21244c2794843ac5a11aae13851b0f2f5106733aa3a3b9cad9
7
- data.tar.gz: 04864770794f7c776af951eab432a4063713b2a2490131a38b13a16d82dece26d4d9547723867045740ff5223233701f42eb855be85d32b51c8b55270b98ba99
6
+ metadata.gz: 60eaeea21dfc61be402f4ca821e2a2d3f3ce6e5f8f7359e57c5591c62f609d20b1ba2f24389694d9e75f83e9e6011dd7651b358380a19e5446f1da128464967c
7
+ data.tar.gz: b1056bf3a13952433b28b7ebb13904d8511bc2e88bd90783dd728468c8d6157406677be137129123e42a61ae43b8578509a49de378d868c6331961ea80aff3f4
@@ -40,13 +40,27 @@ module ActiveRemote
40
40
  def cached_find(argument_hash, options = {})
41
41
  method_name = _cached_find_method_name(argument_hash.keys)
42
42
  arguments = argument_hash.values
43
- __send__(method_name, *arguments, options)
43
+
44
+ if block_given?
45
+ __send__(method_name, *arguments, options) do
46
+ yield
47
+ end
48
+ else
49
+ __send__(method_name, *arguments, options)
50
+ end
44
51
  end
45
52
 
46
53
  def cached_search(argument_hash, options = {})
47
54
  method_name = _cached_search_method_name(argument_hash.keys)
48
55
  arguments = argument_hash.values
49
- __send__(method_name, *arguments, options)
56
+
57
+ if block_given?
58
+ __send__(method_name, *arguments, options) do
59
+ yield
60
+ end
61
+ else
62
+ __send__(method_name, *arguments, options)
63
+ end
50
64
  end
51
65
 
52
66
  ##
@@ -190,11 +204,19 @@ module ActiveRemote
190
204
  # self.find(:user_guid => user_guid)
191
205
  # end
192
206
  # end
207
+ #
208
+ # If a block is given, it is incumbent on the caller to make sure the expectation
209
+ # of the result object is maintained for requests/responses
210
+ #
193
211
  def self.#{method_name}(#{expanded_method_args}, options = {})
194
212
  options = ::ActiveRemote::Cached.default_options.merge(options)
195
213
 
196
214
  ::ActiveRemote::Cached.cache.fetch([name, "#find", #{sorted_method_args}], options) do
197
- self.find(#{expanded_search_args})
215
+ if block_given?
216
+ yield
217
+ else
218
+ self.find(#{expanded_search_args})
219
+ end
198
220
  end
199
221
  end
200
222
  RUBY
@@ -218,11 +240,19 @@ module ActiveRemote
218
240
  # self.search(:user_guid => user_guid)
219
241
  # end
220
242
  # end
243
+ #
244
+ # If a block is given, it is incumbent on the caller to make sure the expectation
245
+ # of the result object is maintained for requests/responses
246
+ #
221
247
  def self.#{method_name}(#{expanded_method_args}, options = {})
222
248
  options = ::ActiveRemote::Cached.default_options.merge(options)
223
249
 
224
250
  ::ActiveRemote::Cached.cache.fetch([name, "#search", #{sorted_method_args}], options) do
225
- self.search(#{expanded_search_args})
251
+ if block_given?
252
+ yield
253
+ else
254
+ self.search(#{expanded_search_args})
255
+ end
226
256
  end
227
257
  end
228
258
  RUBY
@@ -15,8 +15,24 @@ module ActiveRemote::Cached
15
15
  super(@cache_provider)
16
16
  end
17
17
 
18
+ def fetch(name, options = {})
19
+ fetch_value = super
20
+
21
+ unless valid_fetched_value?(fetch_value, options)
22
+ delete(name)
23
+ end
24
+
25
+ return fetch_value
26
+ end
27
+
18
28
  private
19
29
 
30
+ def valid_fetched_value?(value, options = {})
31
+ return false if value.nil?
32
+ return false if !options.fetch(:allow_empty, false) && value.respond_to?(:empty?) && value.empty?
33
+ return true
34
+ end
35
+
20
36
  def validate_provider_method_present(method_name)
21
37
  unless self.cache_provider.respond_to?(method_name)
22
38
  raise <<-CACHE_METHOD
@@ -1,5 +1,5 @@
1
1
  module ActiveRemote
2
2
  module Cached
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  class SearchMethodClass
4
4
  include ::ActiveRemote::Cached
5
5
 
6
+ def self.derp; nil; end
6
7
  def self.find; nil; end
7
8
  def self.search; nil; end
8
9
 
@@ -53,6 +54,54 @@ describe SearchMethodClass do
53
54
  ::ActiveRemote::Cached.default_options({})
54
55
  end
55
56
 
57
+ it "executes the search block when a block is passed" do
58
+ SearchMethodClass.stub(:derp, :derp) do
59
+ SearchMethodClass.cached_search(:guid => :guid) do
60
+ SearchMethodClass.derp
61
+ end.must_equal(:derp)
62
+ end
63
+ end
64
+
65
+ it "does not persist empty values by default" do
66
+ SearchMethodClass.stub(:derp, []) do
67
+ SearchMethodClass.cached_search(:guid => :guid) do
68
+ SearchMethodClass.derp
69
+ end
70
+
71
+ SearchMethodClass.cached_exist_search_by_guid?(:guid).must_equal(false)
72
+ end
73
+ end
74
+
75
+ it "persists empty values when allow_empty sent" do
76
+ SearchMethodClass.stub(:derp, []) do
77
+ SearchMethodClass.cached_search({:guid => :guid}, :allow_empty => true) do
78
+ SearchMethodClass.derp
79
+ end
80
+
81
+ SearchMethodClass.cached_exist_search_by_guid?(:guid).must_equal(true)
82
+ end
83
+ end
84
+
85
+ it "does not persist nil values" do
86
+ SearchMethodClass.stub(:derp, nil) do
87
+ SearchMethodClass.cached_search(:guid => :guid) do
88
+ SearchMethodClass.derp
89
+ end
90
+
91
+ SearchMethodClass.cached_exist_search_by_guid?(:guid).must_equal(false)
92
+ end
93
+ end
94
+
95
+ it "does persist non nil values" do
96
+ SearchMethodClass.stub(:derp, :derp) do
97
+ SearchMethodClass.cached_search(:guid => :guid) do
98
+ SearchMethodClass.derp
99
+ end
100
+
101
+ SearchMethodClass.cached_exist_search_by_guid?(:guid).must_equal(true)
102
+ end
103
+ end
104
+
56
105
  it "executes search_by_guid when cached_search with guid called" do
57
106
  FindMethodClass.stub(:search, :hello) do
58
107
  FindMethodClass.cached_search(:guid => :guid).must_equal(:hello)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_remote-cached
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dewitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-10 00:00:00.000000000 Z
11
+ date: 2014-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_remote
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
- rubygems_version: 2.1.11
139
+ rubygems_version: 2.2.2
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Provides a configuration for caching mechanisms and finders on ActiveRemote