active_remote-cached 0.0.3 → 0.0.4
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 +4 -4
- data/README.md +32 -2
- data/lib/active_remote-cached/version.rb +1 -1
- data/lib/active_remote-cached.rb +49 -15
- data/spec/cached_exist_methods_spec.rb +85 -28
- data/spec/cached_find_methods_spec.rb +2 -2
- data/spec/cached_search_methods_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 037ff5730170b6fd9bcde427a2551d17eada4242
|
4
|
+
data.tar.gz: d7800b6e88135fac587afc65b3f24cd895c6f510
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c23a65bb8c5f8c3fb4d52402be4bc2ad233a402a041574fa29a3fce657fb9b53a0b48b76dbc4fb21244c2794843ac5a11aae13851b0f2f5106733aa3a3b9cad9
|
7
|
+
data.tar.gz: 04864770794f7c776af951eab432a4063713b2a2490131a38b13a16d82dece26d4d9547723867045740ff5223233701f42eb855be85d32b51c8b55270b98ba99
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ActiveRemote::Cached
|
2
2
|
|
3
|
-
|
3
|
+
Provides cached finders for ActiveRemote models that allow a caching provider to cache the result of a query.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,37 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
include `::ActiveRemote::Cached` into your ActiveRemote models that can support cached finders
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class Customer < ::ActiveRemote::Base
|
25
|
+
include ::ActiveRemote::Cached
|
26
|
+
|
27
|
+
# Declare the cached finder methods that will be supported
|
28
|
+
cached_finders_for :id
|
29
|
+
cached_finders_for [:name, :email]
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
Now that you have a model that has cached finders on it you can use the `cached_search`, `cached_find`, or dynamic cached finder methods on the model to use the cache before you issue the AR search/find method.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
customer = ::Customer.cached_find_by_id(1) # => <Customer id=1>
|
37
|
+
customer = ::Customer.cached_find(:id => 1) # => <Customer id=1>
|
38
|
+
customer = ::Customer.cached_search_by_id(1) # => [ <Customer id=1> ]
|
39
|
+
customer = ::Customer.cached_search(:id => 1) # => [ <Customer id=1> ]
|
40
|
+
```
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
# All permutations of "complex" dynamic finders are defined
|
44
|
+
customer = ::Customer.cached_find_by_name_and_email("name", "email") # => <Customer id=1>
|
45
|
+
customer = ::Customer.cached_find_by_email_and_name("email", "name") # => <Customer id=1>
|
46
|
+
|
47
|
+
# Only declared finders are defined
|
48
|
+
customer = ::Customer.cached_find_by_name("name") # => NoMethodError
|
49
|
+
```
|
50
|
+
|
51
|
+
Each finder as takes an optional options hash that will override the options passed to the caching provider (override from the global defaults setup for ActiveRemote::Cached)
|
22
52
|
|
23
53
|
## Contributing
|
24
54
|
|
data/lib/active_remote-cached.rb
CHANGED
@@ -61,7 +61,8 @@ module ActiveRemote
|
|
61
61
|
#
|
62
62
|
cached_finder_key_set.permutation do |arguments|
|
63
63
|
delete_method_name = _cached_delete_method_name(arguments)
|
64
|
-
|
64
|
+
exist_find_method_name = _cached_exist_find_method_name(arguments)
|
65
|
+
exist_search_method_name = _cached_exist_search_method_name(arguments)
|
65
66
|
find_method_name = _cached_find_method_name(arguments)
|
66
67
|
search_method_name = _cached_search_method_name(arguments)
|
67
68
|
|
@@ -69,8 +70,12 @@ module ActiveRemote
|
|
69
70
|
_define_cached_delete_method(delete_method_name, arguments)
|
70
71
|
end
|
71
72
|
|
72
|
-
unless self.respond_to?(
|
73
|
-
|
73
|
+
unless self.respond_to?(exist_find_method_name)
|
74
|
+
_define_cached_exist_find_method(exist_find_method_name, arguments)
|
75
|
+
end
|
76
|
+
|
77
|
+
unless self.respond_to?(exist_search_method_name)
|
78
|
+
_define_cached_exist_search_method(exist_search_method_name, arguments)
|
74
79
|
end
|
75
80
|
|
76
81
|
unless self.respond_to?(find_method_name)
|
@@ -87,8 +92,12 @@ module ActiveRemote
|
|
87
92
|
"cached_delete_by_#{arguments.join('_and_')}"
|
88
93
|
end
|
89
94
|
|
90
|
-
def
|
91
|
-
"
|
95
|
+
def _cached_exist_find_method_name(arguments)
|
96
|
+
"cached_exist_find_by_#{arguments.join('_and_')}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def _cached_exist_search_method_name(arguments)
|
100
|
+
"cached_exist_search_by_#{arguments.join('_and_')}"
|
92
101
|
end
|
93
102
|
|
94
103
|
def _cached_find_method_name(arguments)
|
@@ -109,31 +118,56 @@ module ActiveRemote
|
|
109
118
|
# ::ActiveRemote::Cached.cache.delete([name, user_guid])
|
110
119
|
# end
|
111
120
|
def self.#{method_name}(#{expanded_method_args}, options = {})
|
112
|
-
::ActiveRemote::Cached.cache.delete([name, #{sorted_method_args}])
|
121
|
+
::ActiveRemote::Cached.cache.delete([name, "#search", #{sorted_method_args}])
|
122
|
+
::ActiveRemote::Cached.cache.delete([name, "#find", #{sorted_method_args}])
|
123
|
+
end
|
124
|
+
RUBY
|
125
|
+
end
|
126
|
+
|
127
|
+
def _define_cached_exist_find_method(method_name, *method_arguments)
|
128
|
+
method_arguments.flatten!
|
129
|
+
expanded_method_args = method_arguments.join(",")
|
130
|
+
sorted_method_args = method_arguments.sort.join(",")
|
131
|
+
|
132
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
133
|
+
# def self.cached_exist_find_by_user_guid(user_guid, options = {})
|
134
|
+
# ::ActiveRemote::Cached.cache.exist?([name, user_guid])
|
135
|
+
# end
|
136
|
+
def self.#{method_name}(#{expanded_method_args}, options = {})
|
137
|
+
::ActiveRemote::Cached.cache.exist?([name, "#find", #{sorted_method_args}])
|
138
|
+
end
|
139
|
+
RUBY
|
140
|
+
|
141
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
142
|
+
# def self.cached_exist_find_by_user_guid?(user_guid, options = {})
|
143
|
+
# ::ActiveRemote::Cached.cache.exist?([name, user_guid])
|
144
|
+
# end
|
145
|
+
def self.#{method_name}?(#{expanded_method_args}, options = {})
|
146
|
+
::ActiveRemote::Cached.cache.exist?([name, "#find", #{sorted_method_args}])
|
113
147
|
end
|
114
148
|
RUBY
|
115
149
|
end
|
116
150
|
|
117
|
-
def
|
151
|
+
def _define_cached_exist_search_method(method_name, *method_arguments)
|
118
152
|
method_arguments.flatten!
|
119
153
|
expanded_method_args = method_arguments.join(",")
|
120
154
|
sorted_method_args = method_arguments.sort.join(",")
|
121
155
|
|
122
156
|
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
123
|
-
# def self.
|
157
|
+
# def self.cached_exist_search_by_user_guid(user_guid, options = {})
|
124
158
|
# ::ActiveRemote::Cached.cache.exist?([name, user_guid])
|
125
159
|
# end
|
126
160
|
def self.#{method_name}(#{expanded_method_args}, options = {})
|
127
|
-
::ActiveRemote::Cached.cache.exist?([name, #{sorted_method_args}])
|
161
|
+
::ActiveRemote::Cached.cache.exist?([name, "#search", #{sorted_method_args}])
|
128
162
|
end
|
129
163
|
RUBY
|
130
164
|
|
131
165
|
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
132
|
-
# def self.
|
166
|
+
# def self.cached_exist_search_by_user_guid?(user_guid, options = {})
|
133
167
|
# ::ActiveRemote::Cached.cache.exist?([name, user_guid])
|
134
168
|
# end
|
135
169
|
def self.#{method_name}?(#{expanded_method_args}, options = {})
|
136
|
-
::ActiveRemote::Cached.cache.exist?([name, #{sorted_method_args}])
|
170
|
+
::ActiveRemote::Cached.cache.exist?([name, "#search", #{sorted_method_args}])
|
137
171
|
end
|
138
172
|
RUBY
|
139
173
|
end
|
@@ -152,14 +186,14 @@ module ActiveRemote
|
|
152
186
|
# def self.cached_find_by_user_guid(user_guid, options = {})
|
153
187
|
# options = ::ActiveRemote::Cached.default_options.merge(options)
|
154
188
|
#
|
155
|
-
# ::ActiveRemote::Cached.cache.fetch([name, user_guid], options) do
|
189
|
+
# ::ActiveRemote::Cached.cache.fetch([name, "#find", user_guid], options) do
|
156
190
|
# self.find(:user_guid => user_guid)
|
157
191
|
# end
|
158
192
|
# end
|
159
193
|
def self.#{method_name}(#{expanded_method_args}, options = {})
|
160
194
|
options = ::ActiveRemote::Cached.default_options.merge(options)
|
161
195
|
|
162
|
-
::ActiveRemote::Cached.cache.fetch([name, #{sorted_method_args}], options) do
|
196
|
+
::ActiveRemote::Cached.cache.fetch([name, "#find", #{sorted_method_args}], options) do
|
163
197
|
self.find(#{expanded_search_args})
|
164
198
|
end
|
165
199
|
end
|
@@ -180,14 +214,14 @@ module ActiveRemote
|
|
180
214
|
# def self.cached_search_by_user_guid(user_guid, options = {})
|
181
215
|
# options = ::ActiveRemote::Cached.default_options.merge(options)
|
182
216
|
#
|
183
|
-
# ::ActiveRemote::Cached.cache.fetch([name, user_guid], options) do
|
217
|
+
# ::ActiveRemote::Cached.cache.fetch([name, "#search", user_guid], options) do
|
184
218
|
# self.search(:user_guid => user_guid)
|
185
219
|
# end
|
186
220
|
# end
|
187
221
|
def self.#{method_name}(#{expanded_method_args}, options = {})
|
188
222
|
options = ::ActiveRemote::Cached.default_options.merge(options)
|
189
223
|
|
190
|
-
::ActiveRemote::Cached.cache.fetch([name, #{sorted_method_args}], options) do
|
224
|
+
::ActiveRemote::Cached.cache.fetch([name, "#search", #{sorted_method_args}], options) do
|
191
225
|
self.search(#{expanded_search_args})
|
192
226
|
end
|
193
227
|
end
|
@@ -14,60 +14,117 @@ end
|
|
14
14
|
|
15
15
|
describe ExistMethodClass do
|
16
16
|
describe "API" do
|
17
|
-
it "creates '
|
18
|
-
ExistMethodClass.must_respond_to("
|
17
|
+
it "creates 'cached_exist_find_by_guid'" do
|
18
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_guid")
|
19
19
|
end
|
20
20
|
|
21
|
-
it "creates '
|
22
|
-
ExistMethodClass.must_respond_to("
|
21
|
+
it "creates 'cached_exist_search_by_guid'" do
|
22
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_guid")
|
23
23
|
end
|
24
24
|
|
25
|
-
it "creates '
|
26
|
-
ExistMethodClass.must_respond_to("
|
25
|
+
it "creates 'cached_exist_find_by_user_guid'" do
|
26
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_user_guid")
|
27
27
|
end
|
28
28
|
|
29
|
-
it "creates '
|
30
|
-
ExistMethodClass.must_respond_to("
|
29
|
+
it "creates 'cached_exist_search_by_user_guid'" do
|
30
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_user_guid")
|
31
31
|
end
|
32
32
|
|
33
|
-
it "creates '
|
34
|
-
ExistMethodClass.must_respond_to("
|
33
|
+
it "creates 'cached_exist_find_by_user_guid_and_client_guid'" do
|
34
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_user_guid_and_client_guid")
|
35
35
|
end
|
36
36
|
|
37
|
-
it "creates '
|
38
|
-
ExistMethodClass.must_respond_to("
|
37
|
+
it "creates 'cached_exist_search_by_user_guid_and_client_guid'" do
|
38
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_user_guid_and_client_guid")
|
39
39
|
end
|
40
40
|
|
41
|
-
it "creates '
|
42
|
-
ExistMethodClass.must_respond_to("
|
41
|
+
it "creates 'cached_exist_find_by_client_guid_and_user_guid'" do
|
42
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_client_guid_and_user_guid")
|
43
43
|
end
|
44
44
|
|
45
|
-
it "creates '
|
46
|
-
ExistMethodClass.must_respond_to("
|
45
|
+
it "creates 'cached_exist_search_by_client_guid_and_user_guid'" do
|
46
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_client_guid_and_user_guid")
|
47
47
|
end
|
48
48
|
|
49
|
-
it "creates '
|
50
|
-
ExistMethodClass.must_respond_to("
|
49
|
+
it "creates 'cached_exist_find_by_derp_and_user_guid_and_client_guid'" do
|
50
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_derp_and_user_guid_and_client_guid")
|
51
51
|
end
|
52
52
|
|
53
|
-
it "creates '
|
54
|
-
ExistMethodClass.must_respond_to("
|
53
|
+
it "creates 'cached_exist_search_by_derp_and_user_guid_and_client_guid'" do
|
54
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_derp_and_user_guid_and_client_guid")
|
55
55
|
end
|
56
56
|
|
57
|
-
it "creates '
|
58
|
-
ExistMethodClass.must_respond_to("
|
57
|
+
it "creates 'cached_exist_find_by_client_guid_and_derp_and_user_guid'" do
|
58
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_client_guid_and_derp_and_user_guid")
|
59
59
|
end
|
60
60
|
|
61
|
-
it "creates '
|
62
|
-
ExistMethodClass.must_respond_to("
|
61
|
+
it "creates 'cached_exist_search_by_client_guid_and_derp_and_user_guid'" do
|
62
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_client_guid_and_derp_and_user_guid")
|
63
63
|
end
|
64
64
|
|
65
|
-
it "creates '
|
66
|
-
ExistMethodClass.must_respond_to("
|
65
|
+
it "creates 'cached_exist_find_by_client_guid_and_user_guid_and_derp'" do
|
66
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_client_guid_and_user_guid_and_derp")
|
67
67
|
end
|
68
68
|
|
69
|
-
it "creates '
|
70
|
-
ExistMethodClass.must_respond_to("
|
69
|
+
it "creates 'cached_exist_search_by_client_guid_and_user_guid_and_derp'" do
|
70
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_client_guid_and_user_guid_and_derp")
|
71
|
+
end
|
72
|
+
|
73
|
+
# ? based methods
|
74
|
+
it "creates 'cached_exist_find_by_guid?'" do
|
75
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_guid?")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "creates 'cached_exist_search_by_guid?'" do
|
79
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_guid?")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "creates 'cached_exist_find_by_user_guid?'" do
|
83
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_user_guid?")
|
84
|
+
end
|
85
|
+
|
86
|
+
it "creates 'cached_exist_search_by_user_guid?'" do
|
87
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_user_guid?")
|
88
|
+
end
|
89
|
+
|
90
|
+
it "creates 'cached_exist_find_by_user_guid_and_client_guid?'" do
|
91
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_user_guid_and_client_guid?")
|
92
|
+
end
|
93
|
+
|
94
|
+
it "creates 'cached_exist_search_by_user_guid_and_client_guid?'" do
|
95
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_user_guid_and_client_guid?")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "creates 'cached_exist_find_by_client_guid_and_user_guid?'" do
|
99
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_client_guid_and_user_guid?")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "creates 'cached_exist_search_by_client_guid_and_user_guid?'" do
|
103
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_client_guid_and_user_guid?")
|
104
|
+
end
|
105
|
+
|
106
|
+
it "creates 'cached_exist_find_by_derp_and_user_guid_and_client_guid?'" do
|
107
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_derp_and_user_guid_and_client_guid?")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "creates 'cached_exist_search_by_derp_and_user_guid_and_client_guid?'" do
|
111
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_derp_and_user_guid_and_client_guid?")
|
112
|
+
end
|
113
|
+
|
114
|
+
it "creates 'cached_exist_find_by_client_guid_and_derp_and_user_guid?'" do
|
115
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_client_guid_and_derp_and_user_guid?")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "creates 'cached_exist_search_by_client_guid_and_derp_and_user_guid?'" do
|
119
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_client_guid_and_derp_and_user_guid?")
|
120
|
+
end
|
121
|
+
|
122
|
+
it "creates 'cached_exist_find_by_client_guid_and_user_guid_and_derp?'" do
|
123
|
+
ExistMethodClass.must_respond_to("cached_exist_find_by_client_guid_and_user_guid_and_derp?")
|
124
|
+
end
|
125
|
+
|
126
|
+
it "creates 'cached_exist_search_by_client_guid_and_user_guid_and_derp?'" do
|
127
|
+
ExistMethodClass.must_respond_to("cached_exist_search_by_client_guid_and_user_guid_and_derp?")
|
71
128
|
end
|
72
129
|
end
|
73
130
|
end
|
@@ -66,7 +66,7 @@ describe FindMethodClass do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it "merges the default options in for the fetch call" do
|
69
|
-
::ActiveRemote::Cached.cache.expects(:fetch).with([FindMethodClass.name, :guid], :expires_in => 100).returns(:hello)
|
69
|
+
::ActiveRemote::Cached.cache.expects(:fetch).with([FindMethodClass.name, "#find", :guid], :expires_in => 100).returns(:hello)
|
70
70
|
|
71
71
|
FindMethodClass.stub(:find, :hello) do
|
72
72
|
FindMethodClass.cached_find_by_guid(:guid).must_equal(:hello)
|
@@ -74,7 +74,7 @@ describe FindMethodClass do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
it "overrides the default options with local options for the fetch call" do
|
77
|
-
::ActiveRemote::Cached.cache.expects(:fetch).with([FindMethodClass.name, :guid], :expires_in => 200).returns(:hello)
|
77
|
+
::ActiveRemote::Cached.cache.expects(:fetch).with([FindMethodClass.name, "#find", :guid], :expires_in => 200).returns(:hello)
|
78
78
|
|
79
79
|
FindMethodClass.stub(:find, :hello) do
|
80
80
|
FindMethodClass.cached_find_by_guid(:guid, :expires_in => 200).must_equal(:hello)
|
@@ -66,7 +66,7 @@ describe SearchMethodClass do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it "merges the default options in for the fetch call" do
|
69
|
-
::ActiveRemote::Cached.cache.expects(:fetch).with([SearchMethodClass.name, :guid], :expires_in => 100).returns(:hello)
|
69
|
+
::ActiveRemote::Cached.cache.expects(:fetch).with([SearchMethodClass.name, "#search", :guid], :expires_in => 100).returns(:hello)
|
70
70
|
|
71
71
|
SearchMethodClass.stub(:search, :hello) do
|
72
72
|
SearchMethodClass.cached_search_by_guid(:guid).must_equal(:hello)
|
@@ -74,7 +74,7 @@ describe SearchMethodClass do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
it "overrides the default options with local options for the fetch call" do
|
77
|
-
::ActiveRemote::Cached.cache.expects(:fetch).with([SearchMethodClass.name, :guid], :expires_in => 200).returns(:hello)
|
77
|
+
::ActiveRemote::Cached.cache.expects(:fetch).with([SearchMethodClass.name, "#search", :guid], :expires_in => 200).returns(:hello)
|
78
78
|
|
79
79
|
SearchMethodClass.stub(:search, :hello) do
|
80
80
|
SearchMethodClass.cached_search_by_guid(:guid, :expires_in => 200).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
|
+
version: 0.0.4
|
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-
|
11
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_remote
|