active_remote-cached 0.2.0 → 1.0.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
  SHA256:
3
- metadata.gz: b940a638579d7d52f0802cc3e92b8345135557bd44298fed674a896c885be7dc
4
- data.tar.gz: 651e879207165b7b5ad651f73dabea9035e074f0d15e54ba8b9d6ea3d00d40c6
3
+ metadata.gz: c89a29c20fea4fff1a59ab534285774e7758620a73fc4005866011326b67ddbe
4
+ data.tar.gz: 1fbb57ba895a2aedb8067e399ac747cd6428b2e11c18c043e0fc9fbd8e3a63a1
5
5
  SHA512:
6
- metadata.gz: be9de4a2047ea7fa752e933a2174e7dc8a5ac17a671bb800a2c481295b4a5eaccfd0cb4e90b71ccd091d75892721e91fea4135f6b14e4b956a1256403cbc21e7
7
- data.tar.gz: 316686976d44d6f44731d358602c6b16ab5ce9c781a828f0202b1f68eaedb2bc559720487404f0ade6b2a23b22d37c5ee7d5ee4c5f813cbea30741be58ff388a
6
+ metadata.gz: e07972d8b297ad00be81d09dc05330075db0f744d6d40f0323135f326368846325cc66975f8771260d14ba5cd96156c36e134e9bf500df4bff924d6bdcc9ef82
7
+ data.tar.gz: 5a1818958e13bac846e04616c1762f1fdbb3d7e5e664d8d7c56e86b36e1fa10d608bf242bd666e43ba1bea5eef6f3a17be01e2c1f715bab205413aabe3a764eb
@@ -6,8 +6,8 @@ require 'active_remote/cached/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "active_remote-cached"
8
8
  gem.version = ActiveRemote::Cached::VERSION
9
- gem.authors = ["Brandon Dewitt"]
10
- gem.email = ["brandonsdewitt@gmail.com"]
9
+ gem.authors = ["Brandon Dewitt", "MXDevExperience"]
10
+ gem.email = ["brandonsdewitt@gmail.com", "devexperience@mx.com"]
11
11
  gem.description = %q{ Provides "cached" finders and a DSL to enumerate which finders should have cached versions }
12
12
  gem.summary = %q{ Provides a configuration for caching mechanisms and finders on ActiveRemote models that are cached/cacheable }
13
13
  gem.homepage = ""
@@ -1,5 +1,5 @@
1
1
  module ActiveRemote
2
2
  module Cached
3
- VERSION = "0.2.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -33,6 +33,11 @@ module ActiveRemote
33
33
  end
34
34
 
35
35
  module ClassMethods
36
+ def cached_methods
37
+ @cached_methods ||= []
38
+ @cached_methods
39
+ end
40
+
36
41
  def cached_finders_for(*cached_finder_keys)
37
42
  options = cached_finder_keys.extract_options!
38
43
 
@@ -47,7 +52,7 @@ module ActiveRemote
47
52
 
48
53
  def cached_find(argument_hash, options = {})
49
54
  method_name = _cached_find_method_name(argument_hash.keys)
50
- arguments = argument_hash.values
55
+ arguments = argument_hash.keys.sort.map { |k| argument_hash[k] }
51
56
 
52
57
  if block_given?
53
58
  __send__(method_name, *arguments, options) do
@@ -60,7 +65,7 @@ module ActiveRemote
60
65
 
61
66
  def cached_search(argument_hash, options = {})
62
67
  method_name = _cached_search_method_name(argument_hash.keys)
63
- arguments = argument_hash.values
68
+ arguments = argument_hash.keys.sort.map { |k| argument_hash[k] }
64
69
 
65
70
  if block_given?
66
71
  __send__(method_name, *arguments, options) do
@@ -71,74 +76,131 @@ module ActiveRemote
71
76
  end
72
77
  end
73
78
 
79
+ def method_missing(m, *args, &block)
80
+ method_name = _method_missing_name(m)
81
+
82
+ if method_name.nil? || !cached_methods.include?(method_name.to_s)
83
+ super(m, *args, &block)
84
+ else
85
+ new_args = _args_in_sorted_order(m, args)
86
+ __send__(method_name, *new_args, &block)
87
+ end
88
+ end
89
+
90
+ def respond_to_missing?(m, include_private = false)
91
+ method_name = _method_missing_name(m)
92
+
93
+ if !method_name.nil? && cached_methods.include?(method_name.to_s)
94
+ true
95
+ else
96
+ super
97
+ end
98
+ end
99
+
74
100
  ##
75
101
  # Underscored Methods
76
102
  #
77
- def _create_cached_finder_for(cached_finder_key, options = {})
78
- cached_finder_key_set = [ cached_finder_key ].flatten.sort
103
+ def _method_missing_name(m)
104
+ regex = /(cached_(?:delete|exist_search|search|exist_find|find)_by_)([a-zA-Z_]*)(!|\?)?/
79
105
 
80
- ##
81
- # Run each permutation of the arguments passed in
82
- # and define each finder/searcher
83
- #
84
- cached_finder_key_set.permutation do |arguments|
85
- delete_method_name = _cached_delete_method_name(arguments)
86
- exist_find_method_name = _cached_exist_find_method_name(arguments)
87
- exist_search_method_name = _cached_exist_search_method_name(arguments)
88
- find_method_name = _cached_find_method_name(arguments)
89
- search_method_name = _cached_search_method_name(arguments)
90
- search_bang_method_name = "#{search_method_name}!"
91
-
92
- unless self.respond_to?(delete_method_name)
93
- _define_cached_delete_method(delete_method_name, arguments, options)
94
- end
106
+ if m.to_s =~ regex
107
+ params = $2.split("_and_")
108
+ "#{$1}#{params.sort.join("_and_")}#{$3}".to_sym
109
+ else
110
+ nil
111
+ end
112
+ end
95
113
 
96
- unless self.respond_to?(exist_find_method_name)
97
- _define_cached_exist_find_method(exist_find_method_name, arguments, options)
98
- end
114
+ def _args_in_sorted_order(m, args)
115
+ regex = /cached_(?:delete|exist_search|search|exist_find|find)_by_([a-zA-Z_]*)(!|\?)?/
99
116
 
100
- unless self.respond_to?(exist_search_method_name)
101
- _define_cached_exist_search_method(exist_search_method_name, arguments, options)
102
- end
117
+ method_name = _method_missing_name(m)
103
118
 
104
- unless self.respond_to?(find_method_name)
105
- _define_cached_find_method(find_method_name, arguments, options)
106
- end
119
+ match_1 = m.match(regex)
120
+ match_2 = method_name.match(regex)
107
121
 
108
- unless self.respond_to?(search_bang_method_name)
109
- _define_cached_search_bang_method(search_bang_method_name, arguments, options)
122
+ args_in_order = []
123
+
124
+ if match_1[1] && match_2[1]
125
+ orignal_args_name = match_1[1].split("_and_")
126
+ args_names_in_order = match_2[1].split("_and_")
127
+
128
+ args_names_in_order.each do |arg_name|
129
+ index = orignal_args_name.index(arg_name)
130
+ args_in_order << args[index]
110
131
  end
111
132
 
112
- unless self.respond_to?(search_method_name)
113
- _define_cached_search_method(search_method_name, arguments, options)
133
+ if args.size > args_in_order.size
134
+ # Add options if passed
135
+ args_in_order << args.last
114
136
  end
137
+
138
+ args_in_order
139
+ else
140
+ args
141
+ end
142
+ end
143
+
144
+ def _create_cached_finder_for(cached_finder_key, options = {})
145
+ cached_finder_key_set = [ cached_finder_key ].flatten.sort
146
+
147
+ delete_method_name = _cached_delete_method_name(cached_finder_key_set)
148
+ exist_find_method_name = _cached_exist_find_method_name(cached_finder_key_set)
149
+ exist_search_method_name = _cached_exist_search_method_name(cached_finder_key_set)
150
+ find_method_name = _cached_find_method_name(cached_finder_key_set)
151
+ search_method_name = _cached_search_method_name(cached_finder_key_set)
152
+ search_bang_method_name = "#{search_method_name}!"
153
+
154
+ unless cached_methods.include?(delete_method_name)
155
+ _define_cached_delete_method(delete_method_name, cached_finder_key_set, options)
156
+ end
157
+
158
+ unless cached_methods.include?(exist_find_method_name)
159
+ _define_cached_exist_find_method(exist_find_method_name, cached_finder_key_set, options)
160
+ end
161
+
162
+ unless cached_methods.include?(exist_search_method_name)
163
+ _define_cached_exist_search_method(exist_search_method_name, cached_finder_key_set, options)
164
+ end
165
+
166
+ unless cached_methods.include?(find_method_name)
167
+ _define_cached_find_method(find_method_name, cached_finder_key_set, options)
168
+ end
169
+
170
+ unless cached_methods.include?(search_bang_method_name)
171
+ _define_cached_search_bang_method(search_bang_method_name, cached_finder_key_set, options)
172
+ end
173
+
174
+ unless cached_methods.include?(search_method_name)
175
+ _define_cached_search_method(search_method_name, cached_finder_key_set, options)
115
176
  end
116
177
  end
117
178
 
118
179
  def _cached_delete_method_name(arguments)
119
- "cached_delete_by_#{arguments.join('_and_')}"
180
+ "cached_delete_by_#{arguments.sort.join('_and_')}"
120
181
  end
121
182
 
122
183
  def _cached_exist_find_method_name(arguments)
123
- "cached_exist_find_by_#{arguments.join('_and_')}"
184
+ "cached_exist_find_by_#{arguments.sort.join('_and_')}"
124
185
  end
125
186
 
126
187
  def _cached_exist_search_method_name(arguments)
127
- "cached_exist_search_by_#{arguments.join('_and_')}"
188
+ "cached_exist_search_by_#{arguments.sort.join('_and_')}"
128
189
  end
129
190
 
130
191
  def _cached_find_method_name(arguments)
131
- "cached_find_by_#{arguments.join('_and_')}"
192
+ "cached_find_by_#{arguments.sort.join('_and_')}"
132
193
  end
133
194
 
134
195
  def _cached_search_method_name(arguments)
135
- "cached_search_by_#{arguments.join('_and_')}"
196
+ "cached_search_by_#{arguments.sort.join('_and_')}"
136
197
  end
137
198
 
138
199
  def _define_cached_delete_method(method_name, *method_arguments, cached_finder_options)
139
200
  method_arguments.flatten!
140
201
  expanded_method_args = method_arguments.join(",")
141
202
  sorted_method_args = method_arguments.sort.join(",")
203
+ cached_methods << method_name
142
204
 
143
205
  self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
144
206
  # def self.cached_delete_by_user_guid(user_guid, options = {})
@@ -173,6 +235,8 @@ module ActiveRemote
173
235
  method_arguments.flatten!
174
236
  expanded_method_args = method_arguments.join(",")
175
237
  sorted_method_args = method_arguments.sort.join(",")
238
+ cached_methods << method_name
239
+ cached_methods << "#{method_name}?"
176
240
 
177
241
  self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
178
242
  # def self.cached_exist_find_by_user_guid(user_guid, options = {})
@@ -200,6 +264,8 @@ module ActiveRemote
200
264
  method_arguments.flatten!
201
265
  expanded_method_args = method_arguments.join(",")
202
266
  sorted_method_args = method_arguments.sort.join(",")
267
+ cached_methods << method_name
268
+ cached_methods << "#{method_name}?"
203
269
 
204
270
  self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
205
271
  # def self.cached_exist_search_by_user_guid(user_guid, options = {})
@@ -227,6 +293,7 @@ module ActiveRemote
227
293
  method_arguments.flatten!
228
294
  expanded_method_args = method_arguments.join(",")
229
295
  sorted_method_args = method_arguments.sort.join(",")
296
+ cached_methods << method_name
230
297
 
231
298
  expanded_search_args = ""
232
299
  method_arguments.each do |method_argument|
@@ -271,6 +338,7 @@ module ActiveRemote
271
338
  method_arguments.flatten!
272
339
  expanded_method_args = method_arguments.join(",")
273
340
  sorted_method_args = method_arguments.sort.join(",")
341
+ cached_methods << method_name
274
342
 
275
343
  expanded_search_args = ""
276
344
  method_arguments.each do |method_argument|
@@ -319,6 +387,7 @@ module ActiveRemote
319
387
  method_arguments.flatten!
320
388
  expanded_method_args = method_arguments.join(",")
321
389
  sorted_method_args = method_arguments.sort.join(",")
390
+ cached_methods << method_name
322
391
 
323
392
  expanded_search_args = ""
324
393
  method_arguments.each do |method_argument|
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_remote-cached
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dewitt
8
- autorequire:
8
+ - MXDevExperience
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2020-03-19 00:00:00.000000000 Z
12
+ date: 2024-04-26 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: active_remote
@@ -98,6 +99,7 @@ description: ' Provides "cached" finders and a DSL to enumerate which finders sh
98
99
  have cached versions '
99
100
  email:
100
101
  - brandonsdewitt@gmail.com
102
+ - devexperience@mx.com
101
103
  executables: []
102
104
  extensions: []
103
105
  extra_rdoc_files: []
@@ -124,7 +126,7 @@ files:
124
126
  homepage: ''
125
127
  licenses: []
126
128
  metadata: {}
127
- post_install_message:
129
+ post_install_message:
128
130
  rdoc_options: []
129
131
  require_paths:
130
132
  - lib
@@ -139,8 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
141
  - !ruby/object:Gem::Version
140
142
  version: '0'
141
143
  requirements: []
142
- rubygems_version: 3.0.1
143
- signing_key:
144
+ rubygems_version: 3.3.7
145
+ signing_key:
144
146
  specification_version: 4
145
147
  summary: Provides a configuration for caching mechanisms and finders on ActiveRemote
146
148
  models that are cached/cacheable