active_remote-cached 0.0.8 → 0.0.9

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: 48a4ddc66707e648e15d6860f1d9c464d6b44ace
4
- data.tar.gz: 724bb12c80ccb7dad9e233e6257135d780e872a7
3
+ metadata.gz: 7bf594804579aa384b0224646afcf8feaca70b57
4
+ data.tar.gz: 83749d18cc7ffe032696a2dd7e4667401564d8a9
5
5
  SHA512:
6
- metadata.gz: 7ed6225adc07f144eac3930c81e4ced4efb13c8702d07dce356edd8d4d9cbc6eb4d6fa6992a0eac4086b9a5e98467b14fee2e0f4e4a3c4c5742143685fade71c
7
- data.tar.gz: 6bb63d307f480b31cec87087be46cac64eea5448609ff109c0e6cde434ab8d48c2defbbbf35ffb1527cb579e176ec7742619ac4ee4f095f197284878f1a0fa42
6
+ metadata.gz: 2172bb1d81a714284a9d5211c39dbadbbb4466e588586adad836a9ff3e5848125aa743e8bc062aeac770e73bb904f38108c66ff05741765f80405e49c6b13275
7
+ data.tar.gz: 4f6708a5191b6b4284e896ac9bdbaa84911b49196dabf6676c4a611dbfde277044af807f03c777173e6c65fa076251edb4caf6f226795a4d7516fe2661ce3980
@@ -1,5 +1,5 @@
1
1
  module ActiveRemote
2
2
  module Cached
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
@@ -134,8 +134,13 @@ 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
- ::ActiveRemote::Cached.cache.delete([name, "#search", #{sorted_method_args}])
138
- ::ActiveRemote::Cached.cache.delete([name, "#find", #{sorted_method_args}])
137
+ options = ::ActiveRemote::Cached.default_options.merge(options)
138
+ namespace = options.delete(:namespace)
139
+ find_cache_key = [namespace, name, "#find", #{sorted_method_args}].compact
140
+ search_cache_key = [namespace, name, "#search", #{sorted_method_args}].compact
141
+
142
+ ::ActiveRemote::Cached.cache.delete(find_cache_key)
143
+ ::ActiveRemote::Cached.cache.delete(search_cache_key)
139
144
  end
140
145
  RUBY
141
146
  end
@@ -150,18 +155,15 @@ module ActiveRemote
150
155
  # ::ActiveRemote::Cached.cache.exist?([name, user_guid])
151
156
  # end
152
157
  def self.#{method_name}(#{expanded_method_args}, options = {})
153
- ::ActiveRemote::Cached.cache.exist?([name, "#find", #{sorted_method_args}])
154
- end
155
- RUBY
158
+ options = ::ActiveRemote::Cached.default_options.merge(options)
159
+ namespace = options.delete(:namespace)
160
+ cache_key = [namespace, name, "#find", #{sorted_method_args}].compact
156
161
 
157
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
158
- # def self.cached_exist_find_by_user_guid?(user_guid, options = {})
159
- # ::ActiveRemote::Cached.cache.exist?([name, user_guid])
160
- # end
161
- def self.#{method_name}?(#{expanded_method_args}, options = {})
162
- ::ActiveRemote::Cached.cache.exist?([name, "#find", #{sorted_method_args}])
162
+ ::ActiveRemote::Cached.cache.exist?(cache_key)
163
163
  end
164
164
  RUBY
165
+
166
+ singleton_class.send(:alias_method, "#{method_name}?", method_name)
165
167
  end
166
168
 
167
169
  def _define_cached_exist_search_method(method_name, *method_arguments)
@@ -171,21 +173,18 @@ module ActiveRemote
171
173
 
172
174
  self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
173
175
  # def self.cached_exist_search_by_user_guid(user_guid, options = {})
174
- # ::ActiveRemote::Cached.cache.exist?([name, user_guid])
176
+ # ::ActiveRemote::Cached.cache.exist?([namespace, name, "#search", user_guid])
175
177
  # end
176
178
  def self.#{method_name}(#{expanded_method_args}, options = {})
177
- ::ActiveRemote::Cached.cache.exist?([name, "#search", #{sorted_method_args}])
178
- end
179
- RUBY
179
+ options = ::ActiveRemote::Cached.default_options.merge(options)
180
+ namespace = options.delete(:namespace)
181
+ cache_key = [namespace, name, "#search", #{sorted_method_args}].compact
180
182
 
181
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
182
- # def self.cached_exist_search_by_user_guid?(user_guid, options = {})
183
- # ::ActiveRemote::Cached.cache.exist?([name, user_guid])
184
- # end
185
- def self.#{method_name}?(#{expanded_method_args}, options = {})
186
- ::ActiveRemote::Cached.cache.exist?([name, "#search", #{sorted_method_args}])
183
+ ::ActiveRemote::Cached.cache.exist?(cache_key)
187
184
  end
188
185
  RUBY
186
+
187
+ singleton_class.send(:alias_method, "#{method_name}?", method_name)
189
188
  end
190
189
 
191
190
  def _define_cached_find_method(method_name, *method_arguments)
@@ -202,7 +201,7 @@ module ActiveRemote
202
201
  # def self.cached_find_by_user_guid(user_guid, options = {})
203
202
  # options = ::ActiveRemote::Cached.default_options.merge(options)
204
203
  #
205
- # ::ActiveRemote::Cached.cache.fetch([name, "#find", user_guid], options) do
204
+ # ::ActiveRemote::Cached.cache.fetch([namespace, name, "#find", user_guid], options) do
206
205
  # self.find(:user_guid => user_guid)
207
206
  # end
208
207
  # end
@@ -212,8 +211,10 @@ module ActiveRemote
212
211
  #
213
212
  def self.#{method_name}(#{expanded_method_args}, options = {})
214
213
  options = ::ActiveRemote::Cached.default_options.merge(options)
214
+ namespace = options.delete(:namespace)
215
+ cache_key = [namespace, name, "#find", #{sorted_method_args}].compact
215
216
 
216
- ::ActiveRemote::Cached.cache.fetch([name, "#find", #{sorted_method_args}], options) do
217
+ ::ActiveRemote::Cached.cache.fetch(cache_key, options) do
217
218
  if block_given?
218
219
  yield
219
220
  else
@@ -238,7 +239,7 @@ module ActiveRemote
238
239
  # def self.cached_search_by_user_guid(user_guid, options = {})
239
240
  # options = ::ActiveRemote::Cached.default_options.merge(options)
240
241
  #
241
- # ::ActiveRemote::Cached.cache.fetch([name, "#search", user_guid], options) do
242
+ # ::ActiveRemote::Cached.cache.fetch([namespace, name, "#search", user_guid], options) do
242
243
  # self.search(:user_guid => user_guid)
243
244
  # end
244
245
  # end
@@ -248,8 +249,10 @@ module ActiveRemote
248
249
  #
249
250
  def self.#{method_name}(#{expanded_method_args}, options = {})
250
251
  options = ::ActiveRemote::Cached.default_options.merge(options)
252
+ namespace = options.delete(:namespace)
253
+ cache_key = [namespace, name, "#search", #{sorted_method_args}].compact
251
254
 
252
- ::ActiveRemote::Cached.cache.fetch([name, "#search", #{sorted_method_args}], options) do
255
+ ::ActiveRemote::Cached.cache.fetch(cache_key, options) do
253
256
  if block_given?
254
257
  yield
255
258
  else
@@ -80,5 +80,19 @@ describe FindMethodClass do
80
80
  FindMethodClass.cached_find_by_guid(:guid, :expires_in => 200).must_equal(:hello)
81
81
  end
82
82
  end
83
+
84
+ describe "namespaced cache" do
85
+ before do
86
+ ::ActiveRemote::Cached.default_options(:expires_in => 100, :namespace => "MyApp")
87
+ end
88
+
89
+ it "uses the namespace as a prefix to the cache key" do
90
+ ::ActiveRemote::Cached.cache.expects(:fetch).with(["MyApp", FindMethodClass.name, "#find", :guid], :expires_in => 100).returns(:hello)
91
+
92
+ FindMethodClass.stub(:find, :hello) do
93
+ FindMethodClass.cached_find_by_guid(:guid)
94
+ end
95
+ end
96
+ end
83
97
  end
84
98
  end
@@ -129,5 +129,19 @@ describe SearchMethodClass do
129
129
  SearchMethodClass.cached_search_by_guid(:guid, :expires_in => 200).must_equal(:hello)
130
130
  end
131
131
  end
132
+
133
+ describe "namespaced cache" do
134
+ before do
135
+ ::ActiveRemote::Cached.default_options(:expires_in => 100, :namespace => "MyApp")
136
+ end
137
+
138
+ it "uses the namespace as a prefix to the cache key" do
139
+ ::ActiveRemote::Cached.cache.expects(:fetch).with(["MyApp", SearchMethodClass.name, "#search", :guid], :expires_in => 100).returns(:hello)
140
+
141
+ SearchMethodClass.stub(:search, :hello) do
142
+ SearchMethodClass.cached_search_by_guid(:guid)
143
+ end
144
+ end
145
+ end
132
146
  end
133
147
  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.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dewitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-08 00:00:00.000000000 Z
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_remote