search_me 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/search_me/search.rb +13 -7
- 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: e03e90abe752238a9b064782fb565e89211f08f9
|
4
|
+
data.tar.gz: bca62f59b49be643c18645eb4142468622be78af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96c8fb7d38c11eafc9d747fbc047c51163ec780247a1830d79238970805bc612b238da9586e10a1072fddfffd9f8a48bf606652fbbc508ee0c6a2485733396f1
|
7
|
+
data.tar.gz: 5d4aa289de4ee421e8038ade3632108ac28c9717d16c4900751a230ea5306deb5bfc4bc3bf935a5aba84d78fbd9d9d5b325ab9423ec53576d452611a57d0efe1
|
data/lib/search_me/search.rb
CHANGED
@@ -16,9 +16,11 @@ module SearchMe
|
|
16
16
|
|
17
17
|
# assuming the last attribute could be a hash
|
18
18
|
def attr_search(*attributes)
|
19
|
-
options
|
20
|
-
type
|
21
|
-
|
19
|
+
options = attributes.last.is_a?(Hash) ? attributes.pop : {}
|
20
|
+
type = (options.fetch(:type) { :simple }).to_sym
|
21
|
+
accepted_keys = [:simple] + self.reflections.keys.map(&:to_sym)
|
22
|
+
|
23
|
+
unless accepted_keys.include?(type.to_sym)
|
22
24
|
raise ArgumentError, 'incorect type given'
|
23
25
|
end
|
24
26
|
|
@@ -35,9 +37,9 @@ module SearchMe
|
|
35
37
|
hash[:simple] += attributes
|
36
38
|
hash[:simple] = hash[:simple].uniq
|
37
39
|
else
|
38
|
-
reflection
|
39
|
-
macro
|
40
|
-
klass
|
40
|
+
reflection = indifferent_reflections[type]
|
41
|
+
macro = reflection.macro
|
42
|
+
klass = klass_for_reflection(reflection)
|
41
43
|
|
42
44
|
if macro == :has_many
|
43
45
|
macro = :has_many_through if reflection.options[:through]
|
@@ -176,7 +178,7 @@ module SearchMe
|
|
176
178
|
|
177
179
|
def map_reflection_group(type, outer_block)
|
178
180
|
cond = @this_search_attributes[type].map {|reflection, attributes|
|
179
|
-
reflection =
|
181
|
+
reflection = indifferent_reflections[reflection]
|
180
182
|
klass = klass_for_reflection(reflection)
|
181
183
|
|
182
184
|
reflection_condition = join(yield(attributes,klass,reflection))
|
@@ -293,5 +295,9 @@ module SearchMe
|
|
293
295
|
params.delete(k) if v.blank? && !(v == false)
|
294
296
|
}
|
295
297
|
end
|
298
|
+
|
299
|
+
def indifferent_reflections
|
300
|
+
ActiveSupport::HashWithIndifferentAccess.new(self.reflections)
|
301
|
+
end
|
296
302
|
end
|
297
303
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: search_me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jphager2
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Uses LIKE to search attributes and return any objects of the model for
|
14
14
|
which a match is found
|