search_me 0.0.6 → 0.0.7

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/search_me/search.rb +13 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4dc0217a072a11faf8495a56272dff5b46303e1e
4
- data.tar.gz: 57733d8dfd4cf36396172cc30292fbc31e30f930
3
+ metadata.gz: e03e90abe752238a9b064782fb565e89211f08f9
4
+ data.tar.gz: bca62f59b49be643c18645eb4142468622be78af
5
5
  SHA512:
6
- metadata.gz: a5a9ffa37a4f9d9fab544a86adc9f732a74be138aa2bc7558f9d25aa32d5b082f3ce2f0a532426188934a3ddd21a5201ea853ad291df0007361312976dee7c26
7
- data.tar.gz: 71d3ba7dd7f2994344ee6f892b32d39d5e5c5fc8ac4f045e6b3c3a09725242fdfbd9fac24ef6d98cb4e5b225134c8453f2f53bf21223ee95bf3ea331ebffe48b
6
+ metadata.gz: 96c8fb7d38c11eafc9d747fbc047c51163ec780247a1830d79238970805bc612b238da9586e10a1072fddfffd9f8a48bf606652fbbc508ee0c6a2485733396f1
7
+ data.tar.gz: 5d4aa289de4ee421e8038ade3632108ac28c9717d16c4900751a230ea5306deb5bfc4bc3bf935a5aba84d78fbd9d9d5b325ab9423ec53576d452611a57d0efe1
@@ -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 = attributes.last.is_a?(Hash) ? attributes.pop : {}
20
- type = options.fetch(:type) { :simple }
21
- unless ([:simple] + self.reflections.keys).include?(type)
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 = self.reflections[type]
39
- macro = reflection.macro
40
- klass = klass_for_reflection(reflection)
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 = self.reflections[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.6
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-30 00:00:00.000000000 Z
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