active_remote-cached 0.1.0 → 0.1.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0c37d8fe5adf8a1227c97dddf83db2eb5d59fc7
|
4
|
+
data.tar.gz: 49690fa347012f5dd569dd1ce175f864adf83b6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 553ee8882228bb293410908ef21f4c40b7decc3fa2d0a4f40adfe42d83191c2c0649266b3e7db69782f42943cdeb42dead439ebeeed9461fac2f7da02da1ebfd
|
7
|
+
data.tar.gz: 42ca67feb1eddc71a2f679e4ab04453811c12d63810486adb0290d78245b4c2ad0e88ef31fa81ebab5dd7ff4afc7456e4754a9e4aee53cd2131c52a05de06c8f
|
data/lib/active_remote/cached.rb
CHANGED
@@ -83,23 +83,23 @@ module ActiveRemote
|
|
83
83
|
search_method_name = _cached_search_method_name(arguments)
|
84
84
|
|
85
85
|
unless self.respond_to?(delete_method_name)
|
86
|
-
_define_cached_delete_method(delete_method_name, arguments)
|
86
|
+
_define_cached_delete_method(delete_method_name, arguments, options)
|
87
87
|
end
|
88
88
|
|
89
89
|
unless self.respond_to?(exist_find_method_name)
|
90
|
-
_define_cached_exist_find_method(exist_find_method_name, arguments)
|
90
|
+
_define_cached_exist_find_method(exist_find_method_name, arguments, options)
|
91
91
|
end
|
92
92
|
|
93
93
|
unless self.respond_to?(exist_search_method_name)
|
94
|
-
_define_cached_exist_search_method(exist_search_method_name, arguments)
|
94
|
+
_define_cached_exist_search_method(exist_search_method_name, arguments, options)
|
95
95
|
end
|
96
96
|
|
97
97
|
unless self.respond_to?(find_method_name)
|
98
|
-
_define_cached_find_method(find_method_name, arguments)
|
98
|
+
_define_cached_find_method(find_method_name, arguments, options)
|
99
99
|
end
|
100
100
|
|
101
101
|
unless self.respond_to?(search_method_name)
|
102
|
-
_define_cached_search_method(search_method_name, arguments)
|
102
|
+
_define_cached_search_method(search_method_name, arguments, options)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
@@ -124,7 +124,7 @@ module ActiveRemote
|
|
124
124
|
"cached_search_by_#{arguments.join('_and_')}"
|
125
125
|
end
|
126
126
|
|
127
|
-
def _define_cached_delete_method(method_name, *method_arguments)
|
127
|
+
def _define_cached_delete_method(method_name, *method_arguments, cached_finder_options)
|
128
128
|
method_arguments.flatten!
|
129
129
|
expanded_method_args = method_arguments.join(",")
|
130
130
|
sorted_method_args = method_arguments.sort.join(",")
|
@@ -134,7 +134,7 @@ module ActiveRemote
|
|
134
134
|
# ::ActiveRemote::Cached.cache.delete([name, user_guid])
|
135
135
|
# end
|
136
136
|
def self.#{method_name}(#{expanded_method_args}, options = {})
|
137
|
-
options = ::ActiveRemote::Cached.default_options.merge(options)
|
137
|
+
options = ::ActiveRemote::Cached.default_options.merge(#{cached_finder_options}).merge(options)
|
138
138
|
namespace = options.delete(:namespace)
|
139
139
|
find_cache_key = [namespace, name, "#find", #{sorted_method_args}].compact
|
140
140
|
search_cache_key = [namespace, name, "#search", #{sorted_method_args}].compact
|
@@ -145,7 +145,7 @@ module ActiveRemote
|
|
145
145
|
RUBY
|
146
146
|
end
|
147
147
|
|
148
|
-
def _define_cached_exist_find_method(method_name, *method_arguments)
|
148
|
+
def _define_cached_exist_find_method(method_name, *method_arguments, cached_finder_options)
|
149
149
|
method_arguments.flatten!
|
150
150
|
expanded_method_args = method_arguments.join(",")
|
151
151
|
sorted_method_args = method_arguments.sort.join(",")
|
@@ -155,7 +155,7 @@ module ActiveRemote
|
|
155
155
|
# ::ActiveRemote::Cached.cache.exist?([name, user_guid])
|
156
156
|
# end
|
157
157
|
def self.#{method_name}(#{expanded_method_args}, options = {})
|
158
|
-
options = ::ActiveRemote::Cached.default_options.merge(options)
|
158
|
+
options = ::ActiveRemote::Cached.default_options.merge(#{cached_finder_options}).merge(options)
|
159
159
|
namespace = options.delete(:namespace)
|
160
160
|
cache_key = [namespace, name, "#find", #{sorted_method_args}].compact
|
161
161
|
|
@@ -166,7 +166,7 @@ module ActiveRemote
|
|
166
166
|
singleton_class.send(:alias_method, "#{method_name}?", method_name)
|
167
167
|
end
|
168
168
|
|
169
|
-
def _define_cached_exist_search_method(method_name, *method_arguments)
|
169
|
+
def _define_cached_exist_search_method(method_name, *method_arguments, cached_finder_options)
|
170
170
|
method_arguments.flatten!
|
171
171
|
expanded_method_args = method_arguments.join(",")
|
172
172
|
sorted_method_args = method_arguments.sort.join(",")
|
@@ -176,7 +176,7 @@ module ActiveRemote
|
|
176
176
|
# ::ActiveRemote::Cached.cache.exist?([namespace, name, "#search", user_guid])
|
177
177
|
# end
|
178
178
|
def self.#{method_name}(#{expanded_method_args}, options = {})
|
179
|
-
options = ::ActiveRemote::Cached.default_options.merge(options)
|
179
|
+
options = ::ActiveRemote::Cached.default_options.merge(#{cached_finder_options}).merge(options)
|
180
180
|
namespace = options.delete(:namespace)
|
181
181
|
cache_key = [namespace, name, "#search", #{sorted_method_args}].compact
|
182
182
|
|
@@ -187,7 +187,7 @@ module ActiveRemote
|
|
187
187
|
singleton_class.send(:alias_method, "#{method_name}?", method_name)
|
188
188
|
end
|
189
189
|
|
190
|
-
def _define_cached_find_method(method_name, *method_arguments)
|
190
|
+
def _define_cached_find_method(method_name, *method_arguments, cached_finder_options)
|
191
191
|
method_arguments.flatten!
|
192
192
|
expanded_method_args = method_arguments.join(",")
|
193
193
|
sorted_method_args = method_arguments.sort.join(",")
|
@@ -199,7 +199,7 @@ module ActiveRemote
|
|
199
199
|
|
200
200
|
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
201
201
|
# def self.cached_find_by_user_guid(user_guid, options = {})
|
202
|
-
# options = ::ActiveRemote::Cached.default_options.merge(options)
|
202
|
+
# options = ::ActiveRemote::Cached.default_options.merge({}).merge(options)
|
203
203
|
#
|
204
204
|
# ::ActiveRemote::Cached.cache.fetch([namespace, name, "#find", user_guid], options) do
|
205
205
|
# self.find(:user_guid => user_guid)
|
@@ -210,7 +210,7 @@ module ActiveRemote
|
|
210
210
|
# of the result object is maintained for requests/responses
|
211
211
|
#
|
212
212
|
def self.#{method_name}(#{expanded_method_args}, options = {})
|
213
|
-
options = ::ActiveRemote::Cached.default_options.merge(options)
|
213
|
+
options = ::ActiveRemote::Cached.default_options.merge(#{cached_finder_options}).merge(options)
|
214
214
|
namespace = options.delete(:namespace)
|
215
215
|
cache_key = [namespace, name, "#find", #{sorted_method_args}].compact
|
216
216
|
|
@@ -225,7 +225,7 @@ module ActiveRemote
|
|
225
225
|
RUBY
|
226
226
|
end
|
227
227
|
|
228
|
-
def _define_cached_search_method(method_name, *method_arguments)
|
228
|
+
def _define_cached_search_method(method_name, *method_arguments, cached_finder_options)
|
229
229
|
method_arguments.flatten!
|
230
230
|
expanded_method_args = method_arguments.join(",")
|
231
231
|
sorted_method_args = method_arguments.sort.join(",")
|
@@ -237,7 +237,7 @@ module ActiveRemote
|
|
237
237
|
|
238
238
|
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
239
239
|
# def self.cached_search_by_user_guid(user_guid, options = {})
|
240
|
-
# options = ::ActiveRemote::Cached.default_options.merge(options)
|
240
|
+
# options = ::ActiveRemote::Cached.default_options.merge({}).merge(options)
|
241
241
|
#
|
242
242
|
# ::ActiveRemote::Cached.cache.fetch([namespace, name, "#search", user_guid], options) do
|
243
243
|
# self.search(:user_guid => user_guid)
|
@@ -248,7 +248,7 @@ module ActiveRemote
|
|
248
248
|
# of the result object is maintained for requests/responses
|
249
249
|
#
|
250
250
|
def self.#{method_name}(#{expanded_method_args}, options = {})
|
251
|
-
options = ::ActiveRemote::Cached.default_options.merge(options)
|
251
|
+
options = ::ActiveRemote::Cached.default_options.merge(#{cached_finder_options}).merge(options)
|
252
252
|
namespace = options.delete(:namespace)
|
253
253
|
cache_key = [namespace, name, "#search", #{sorted_method_args}].compact
|
254
254
|
|
@@ -6,6 +6,7 @@ class FindMethodClass
|
|
6
6
|
def self.find; nil; end
|
7
7
|
def self.search; nil; end
|
8
8
|
|
9
|
+
cached_finders_for :foo, :expires_in => 500
|
9
10
|
cached_finders_for :guid
|
10
11
|
cached_finders_for :guid, :user_guid
|
11
12
|
cached_finders_for [:user_guid, :client_guid]
|
@@ -14,6 +15,10 @@ end
|
|
14
15
|
|
15
16
|
describe FindMethodClass do
|
16
17
|
describe "API" do
|
18
|
+
it "creates 'cached_find_by_foo'" do
|
19
|
+
FindMethodClass.must_respond_to("cached_find_by_foo")
|
20
|
+
end
|
21
|
+
|
17
22
|
it "creates 'cached_find_by_guid'" do
|
18
23
|
FindMethodClass.must_respond_to("cached_find_by_guid")
|
19
24
|
end
|
@@ -95,4 +100,31 @@ describe FindMethodClass do
|
|
95
100
|
end
|
96
101
|
end
|
97
102
|
end
|
103
|
+
|
104
|
+
describe "#cached_find_by_foo" do
|
105
|
+
before do
|
106
|
+
::ActiveRemote::Cached.cache(HashCache.new)
|
107
|
+
::ActiveRemote::Cached.default_options(:expires_in => 100)
|
108
|
+
end
|
109
|
+
|
110
|
+
after do
|
111
|
+
::ActiveRemote::Cached.default_options({})
|
112
|
+
end
|
113
|
+
|
114
|
+
it "overrides the default options with cached_finder options for the fetch call" do
|
115
|
+
::ActiveRemote::Cached.cache.expects(:fetch).with([FindMethodClass.name, "#find", :foo], :expires_in => 500).returns(:hello)
|
116
|
+
|
117
|
+
FindMethodClass.stub(:find, :hello) do
|
118
|
+
FindMethodClass.cached_find_by_foo(:foo).must_equal(:hello)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
it "overrides the cached_finder options with local options for the fetch call" do
|
123
|
+
::ActiveRemote::Cached.cache.expects(:fetch).with([FindMethodClass.name, "#find", :foo], :expires_in => 200).returns(:hello)
|
124
|
+
|
125
|
+
FindMethodClass.stub(:find, :hello) do
|
126
|
+
FindMethodClass.cached_find_by_foo(:foo, :expires_in => 200).must_equal(:hello)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
98
130
|
end
|
@@ -7,6 +7,7 @@ class SearchMethodClass
|
|
7
7
|
def self.find; nil; end
|
8
8
|
def self.search; nil; end
|
9
9
|
|
10
|
+
cached_finders_for :foo, :expires_in => 500
|
10
11
|
cached_finders_for :guid
|
11
12
|
cached_finders_for :guid, :user_guid
|
12
13
|
cached_finders_for [:user_guid, :client_guid]
|
@@ -15,6 +16,10 @@ end
|
|
15
16
|
|
16
17
|
describe SearchMethodClass do
|
17
18
|
describe "API" do
|
19
|
+
it "creates 'cached_search_by_foo'" do
|
20
|
+
SearchMethodClass.must_respond_to("cached_search_by_foo")
|
21
|
+
end
|
22
|
+
|
18
23
|
it "creates 'cached_search_by_guid'" do
|
19
24
|
SearchMethodClass.must_respond_to("cached_search_by_guid")
|
20
25
|
end
|
@@ -144,4 +149,31 @@ describe SearchMethodClass do
|
|
144
149
|
end
|
145
150
|
end
|
146
151
|
end
|
152
|
+
|
153
|
+
describe "#cached_search_by_foo" do
|
154
|
+
before do
|
155
|
+
::ActiveRemote::Cached.cache(HashCache.new)
|
156
|
+
::ActiveRemote::Cached.default_options(:expires_in => 100)
|
157
|
+
end
|
158
|
+
|
159
|
+
after do
|
160
|
+
::ActiveRemote::Cached.default_options({})
|
161
|
+
end
|
162
|
+
|
163
|
+
it "overrides the default options with cached_finder options for the fetch call" do
|
164
|
+
::ActiveRemote::Cached.cache.expects(:fetch).with([SearchMethodClass.name, "#search", :foo], :expires_in => 500).returns(:hello)
|
165
|
+
|
166
|
+
SearchMethodClass.stub(:find, :hello) do
|
167
|
+
SearchMethodClass.cached_search_by_foo(:foo).must_equal(:hello)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
it "overrides the cached_finder options with local options for the fetch call" do
|
172
|
+
::ActiveRemote::Cached.cache.expects(:fetch).with([SearchMethodClass.name, "#search", :foo], :expires_in => 200).returns(:hello)
|
173
|
+
|
174
|
+
SearchMethodClass.stub(:find, :hello) do
|
175
|
+
SearchMethodClass.cached_search_by_foo(:foo, :expires_in => 200).must_equal(:hello)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
147
179
|
end
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Dewitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_remote
|