looksist 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: 41b6c0fcd98079a67f6419de4bdf1bad8a372e67
4
- data.tar.gz: 2bcfde54ae2c0b0fbe097202b7d23609c3401c3f
3
+ metadata.gz: 6104d9b264565171b9c36c00f2ed77c92f032f1a
4
+ data.tar.gz: d8b49f214f2e2a06a107597d14f430064f451c13
5
5
  SHA512:
6
- metadata.gz: 3e35bc8d5a4fdf61d2b4136812101f61bfb2b1c191b56300f38954a07d4eda7675b8872b42ab3e75317b2e6429918d7b3510fe6986c5017f05b5e67db821246f
7
- data.tar.gz: dfb89beceb5981d66fcfa128e6e2d17e4f09e781abd98375b55ef9d8048b8a422cde3f6c35a945353a4868dfe077fc3c2ea40d29d7051db2cc6f392b25d7fac7
6
+ metadata.gz: 00c77002c2b385a4dcebe00cf88b63beab0e952c4561081c712cf2e556c39f060b716637d7bc590f0c5a80638124f5f3a67782a9167291f3d2a31b8060cbc13b
7
+ data.tar.gz: e5fb28133d5630f8b2b0f1d52a8f9bdb7945d81876f4994204cb68d280f58060268e8053500b54a8c641994fa49cd6c6fbb24ece6cf996445260f41cc0760e71
@@ -14,29 +14,28 @@ module Looksist
14
14
  @rules ||= {}
15
15
  (@rules[after] ||= []) << opts
16
16
 
17
- return if @rules[after].length > 1
18
-
19
- define_method("#{after}_with_inject") do |*args|
20
- hash = send("#{after}_without_inject".to_sym, *args)
21
- self.class.instance_variable_get(:@rules)[after].each do |opts|
22
- if opts[:at].is_a? String
23
- hash = JsonPath.for(hash.with_indifferent_access).gsub!(opts[:at]) do |i|
24
- i.is_a?(Array) ? inject_attributes_for(i, opts) : inject_attributes_at(i, opts) unless i.empty?
25
- i
26
- end.to_hash.deep_symbolize_keys
27
- else
28
- inject_attributes_at(hash[opts[:at]], opts)
17
+ unless @rules[after].length > 1
18
+ define_method("#{after}_with_inject") do |*args|
19
+ hash = send("#{after}_without_inject".to_sym, *args)
20
+ self.class.instance_variable_get(:@rules)[after].each do |opts|
21
+ if opts[:at].is_a? String
22
+ hash = update_using_json_path(hash, opts).to_hash.deep_symbolize_keys
23
+ else
24
+ inject_attributes_at(hash[opts[:at]], opts)
25
+ end
29
26
  end
27
+ hash
30
28
  end
31
- hash
29
+ alias_method_chain after, :inject
32
30
  end
33
- alias_method_chain after, :inject
34
-
35
31
  end
32
+
33
+
36
34
  end
37
35
 
38
36
  included do |base|
39
37
  base.class_attribute :rules
38
+ base.rules = {}
40
39
  end
41
40
 
42
41
  private
@@ -50,6 +49,13 @@ module Looksist
50
49
  hash_offset
51
50
  end
52
51
 
52
+ def update_using_json_path(hash, opts)
53
+ JsonPath.for(hash.with_indifferent_access).gsub!(opts[:at]) do |i|
54
+ i.is_a?(Array) ? inject_attributes_for(i, opts) : inject_attributes_at(i, opts) unless i.empty?
55
+ i
56
+ end
57
+ end
58
+
53
59
  def inject_attributes_for(arry_of_hashes, opts)
54
60
  entity_name = __entity__(opts[:bucket_name] || opts[:using])
55
61
  keys = (arry_of_hashes.collect { |i| i[opts[:using]] }).compact.uniq
@@ -1,3 +1,3 @@
1
1
  module Lookist
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - RC