looksist 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/looksist/hashed.rb +29 -29
- data/lib/looksist/version.rb +1 -1
- data/spec/looksist/hashed_spec.rb +23 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53a388186cedd458e2dab2eecb8b05e9351c81a4
|
4
|
+
data.tar.gz: 9709f69d2f4ba76a3f3ef6e24e04d5f74d628c0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ccc8051b94102c289c1e5a9463707ef559e7d82ab0e2a35fb11730ac5977dd8bab91c1a09a31caf45fc013d5e28e0804d158b91e15c2e273aff34fc04dab536
|
7
|
+
data.tar.gz: 9af59f885b033c6f8da30ad4d0faba4edc3d305cce38ba5cff2758ed4a0954ae72573cba46196a8156ac64992d4867212f5bf80dd5c296d94c70891f20bde724
|
data/README.md
CHANGED
@@ -221,7 +221,7 @@ it 'should inject multiple attribute to an existing deep hash for class methods'
|
|
221
221
|
}
|
222
222
|
end
|
223
223
|
|
224
|
-
|
224
|
+
inject after: :metrics, at: '$.table.database',
|
225
225
|
using: :employee_id, populate: :employee_name
|
226
226
|
|
227
227
|
end
|
data/lib/looksist/hashed.rb
CHANGED
@@ -15,42 +15,42 @@ module Looksist
|
|
15
15
|
(@rules[after] ||= []) << opts
|
16
16
|
|
17
17
|
unless @rules[after].length > 1
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
hash = self.class.update_using_json_path(hash, opts)
|
23
|
-
else
|
24
|
-
self.class.inject_attributes_at(hash[opts[:at]], opts)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
hash
|
18
|
+
if self.singleton_methods.include?(after)
|
19
|
+
inject_class_methods(after)
|
20
|
+
else
|
21
|
+
inject_instance_methods(after)
|
28
22
|
end
|
29
|
-
alias_method_chain after, :inject
|
30
23
|
end
|
31
24
|
end
|
32
25
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
26
|
+
def inject_instance_methods(after)
|
27
|
+
define_method("#{after}_with_inject") do |*args|
|
28
|
+
hash = send("#{after}_without_inject".to_sym, *args)
|
29
|
+
self.class.instance_variable_get(:@rules)[after].each do |opts|
|
30
|
+
if opts[:at].nil? or opts[:at].is_a? String
|
31
|
+
hash = self.class.update_using_json_path(hash, opts)
|
32
|
+
else
|
33
|
+
self.class.inject_attributes_at(hash[opts[:at]], opts)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
hash
|
37
|
+
end
|
38
|
+
alias_method_chain after, :inject
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
41
|
+
def inject_class_methods(after)
|
42
|
+
define_singleton_method("#{after}_with_inject") do |*args|
|
43
|
+
hash = send("#{after}_without_inject".to_sym, *args)
|
44
|
+
@rules[after].each do |opts|
|
45
|
+
if opts[:at].nil? or opts[:at].is_a? String
|
46
|
+
hash = update_using_json_path(hash, opts)
|
47
|
+
else
|
48
|
+
inject_attributes_at(hash[opts[:at]], opts)
|
49
49
|
end
|
50
|
-
hash
|
51
50
|
end
|
52
|
-
|
51
|
+
hash
|
53
52
|
end
|
53
|
+
self.singleton_class.send(:alias_method_chain, after, :inject)
|
54
54
|
end
|
55
55
|
|
56
56
|
def inject_attributes_at(hash_offset, opts)
|
@@ -71,7 +71,7 @@ module Looksist
|
|
71
71
|
i
|
72
72
|
end
|
73
73
|
else
|
74
|
-
|
74
|
+
inject_attributes_at(hash, opts)
|
75
75
|
|
76
76
|
end.to_hash.deep_symbolize_keys
|
77
77
|
else
|
data/lib/looksist/version.rb
CHANGED
@@ -464,12 +464,31 @@ describe Looksist::Hashed do
|
|
464
464
|
]
|
465
465
|
end
|
466
466
|
|
467
|
-
|
467
|
+
inject after: :help_me, at: '$', using: :a, bucket_name: 'ids', populate: :name
|
468
468
|
end
|
469
469
|
|
470
|
-
expect(@mock).to receive(:mget).once.with('ids/1').and_return(['
|
471
|
-
expect(SelfHelp.help_me).to eq([{:a => 1, :name => "
|
470
|
+
expect(@mock).to receive(:mget).once.with('ids/1').and_return(['RajiniKanth'])
|
471
|
+
expect(SelfHelp.help_me).to eq([{:a => 1, :name => "RajiniKanth"}])
|
472
|
+
end
|
473
|
+
|
474
|
+
it 'should work for first level hashes in class methods' do
|
475
|
+
class FirstLevelClass
|
476
|
+
include Looksist
|
477
|
+
|
478
|
+
class << self
|
479
|
+
def my_method
|
480
|
+
{
|
481
|
+
a: 1
|
482
|
+
}
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
inject after: :my_method, using: :a, bucket_name: 'ids', populate: :name
|
487
|
+
end
|
488
|
+
|
489
|
+
expect(@mock).to receive(:get).once.with('ids/1').and_return('RajiniKanth')
|
490
|
+
expect(FirstLevelClass.my_method).to eq({:a => 1, :name => "RajiniKanth"})
|
472
491
|
end
|
473
492
|
|
474
493
|
end
|
475
|
-
end
|
494
|
+
end
|