looksist 0.3.7 → 0.3.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35a51afb4989fbb14f003fa155e50e14afb90439
4
- data.tar.gz: 4295b2ff68f81062ab5d2911302de3998a0d22f2
3
+ metadata.gz: 1ed8d09b1e799bb4e40b66a065fbe39ed049e423
4
+ data.tar.gz: eeec8b9db71d9a12c63cfaa18880c084a169a2b2
5
5
  SHA512:
6
- metadata.gz: 179e3288026145a68f0548aed4e284d104b92354db7583cba9f64b463d627094efacb2cf8ae73d6f865974a4c78dbfccf68aae00ff510203fcc445a7ee188308
7
- data.tar.gz: a664389618be8eb5f89032d69ba1ddfd422b2c3868b13572f3b6b1be8388e8315709927adb1dc9c072e8c47e69171517ee1d8337f422e77d5e7fcda751c0f8d7
6
+ metadata.gz: e28f0f4283e7aed483bcda0ba3f377b3267570d647ee4362d8a4ab16611afbfd2d363103a9b2271a140fec65894d10ce01273f35853f2127ea5e918b656a2294
7
+ data.tar.gz: b22b1798d96ab7484845ebb4a42b819754680c150d29edcc7124b2a09e6c61100bb32474ef687ffd30cfab688ef30f189b19ad56f904a68d268ef7380284cd17
@@ -1,4 +1,5 @@
1
1
  require 'looksist/version'
2
+ require 'looksist/hash'
2
3
  require 'jsonpath'
3
4
  require 'looksist/common'
4
5
  require 'looksist/core'
@@ -0,0 +1,13 @@
1
+ class Hash
2
+ def find_all_values_for(key)
3
+ result = []
4
+ result << self[key]
5
+ self.values.each do |hash_value|
6
+ values = (hash_value.is_a?(Array) ? hash_value : [hash_value])
7
+ values.each do |value|
8
+ result += value.find_all_values_for(key) if value.is_a? Hash
9
+ end
10
+ end
11
+ result.compact
12
+ end
13
+ end
@@ -108,8 +108,7 @@ module Looksist
108
108
  modified_array = if at.nil?
109
109
  array_of_hashes.map(&:values)
110
110
  else
111
- json_path = JsonPath.new("#{at}..#{opt[:using]}")
112
- json_path.on(array_of_hashes.to_json)
111
+ extract_values(array_of_hashes, opt[:using])
113
112
  end
114
113
  keys = modified_array.flatten.compact.uniq
115
114
  values = Hash[keys.zip(Looksist.redis_service.send("#{entity_name}_for", keys))]
@@ -118,6 +117,11 @@ module Looksist
118
117
  smart_lookup(array_of_hashes, opts, all_values, at)
119
118
  end
120
119
 
120
+ def extract_values(array_of_hashes, using)
121
+ hash = array_of_hashes.is_a?(Array) ? {:root => array_of_hashes} : array_of_hashes
122
+ hash.find_all_values_for(using)
123
+ end
124
+
121
125
  def smart_lookup(array_of_hashes, opts, all_values, at)
122
126
  ## populate is not a array
123
127
  array_of_hashes.collect do |elt|
@@ -1,3 +1,3 @@
1
1
  module Lookist
2
- VERSION = '0.3.7'
2
+ VERSION = '0.3.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: looksist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - RC
@@ -210,6 +210,7 @@ files:
210
210
  - lib/looksist.rb
211
211
  - lib/looksist/common.rb
212
212
  - lib/looksist/core.rb
213
+ - lib/looksist/hash.rb
213
214
  - lib/looksist/hashed.rb
214
215
  - lib/looksist/redis_service.rb
215
216
  - lib/looksist/safe_lru_cache.rb