looksist 0.3.11 → 0.3.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/looksist/core.rb +6 -1
- data/lib/looksist/hashed.rb +6 -1
- data/lib/looksist/version.rb +1 -1
- data/spec/looksist/hashed_spec.rb +27 -0
- data/spec/looksist/looksist_spec.rb +18 -0
- 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: 9f63a1c36d1bac556df87d59b84e56d3cb912864
|
4
|
+
data.tar.gz: bda04de8e57710e3aeb2c7f48b8b75b53cf947a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86f43387109482d62aec666accbb5b68bb10c25e7ba30d6eead747aa9970f4bf5f0d2e24f64126af2dec368834db791b7f590983c8b4ec88892526d1828f4018
|
7
|
+
data.tar.gz: 6a1c54940cf6592d5eac3358f755838a3b64222bb46a4a2bedb3151cd4c831926895916d94ef5f8800cb220ece2bd77ab3391d8cd1b373ffadf72b849cb66d57
|
data/lib/looksist/core.rb
CHANGED
@@ -19,7 +19,12 @@ module Looksist
|
|
19
19
|
alias_what = find_alias(as, what)
|
20
20
|
@lookup_attributes[alias_what] = opts[:using]
|
21
21
|
define_method(alias_what) do
|
22
|
-
Looksist.redis_service.send("#{__entity__(bucket_name)}_for", self.send(using).try(:to_s))
|
22
|
+
result = Looksist.redis_service.send("#{__entity__(bucket_name)}_for", self.send(using).try(:to_s))
|
23
|
+
begin
|
24
|
+
JSON.parse(result)[what.to_s]
|
25
|
+
rescue
|
26
|
+
result
|
27
|
+
end
|
23
28
|
end
|
24
29
|
end
|
25
30
|
end
|
data/lib/looksist/hashed.rb
CHANGED
@@ -161,7 +161,12 @@ module Looksist
|
|
161
161
|
end
|
162
162
|
else
|
163
163
|
alias_method = find_alias(as, populate)
|
164
|
-
|
164
|
+
begin
|
165
|
+
json = JSON.parse(values[elt.with_indifferent_access[using]])
|
166
|
+
elt[alias_method] = json.with_indifferent_access[populate]
|
167
|
+
rescue
|
168
|
+
elt[alias_method] = values[elt.with_indifferent_access[using]]
|
169
|
+
end
|
165
170
|
end
|
166
171
|
end
|
167
172
|
|
data/lib/looksist/version.rb
CHANGED
@@ -507,6 +507,33 @@ describe Looksist::Hashed do
|
|
507
507
|
)
|
508
508
|
end
|
509
509
|
|
510
|
+
it 'should work for multiple attributes but looking up only one attribute' do
|
511
|
+
class HashWithMultipleAttributesLookUpOne
|
512
|
+
include Looksist
|
513
|
+
|
514
|
+
def metrics
|
515
|
+
[
|
516
|
+
{
|
517
|
+
hero_id: 1
|
518
|
+
},
|
519
|
+
{
|
520
|
+
hero_id: 2
|
521
|
+
}
|
522
|
+
]
|
523
|
+
end
|
524
|
+
|
525
|
+
inject after: :metrics, using: :hero_id, populate: :name, as: {name: 'hero_name'}
|
526
|
+
end
|
527
|
+
js1 = {name: 'Rajini', mnemonic: 'SuperStart'}.to_json
|
528
|
+
jsons = [js1, nil]
|
529
|
+
expect(@mock).to receive(:mget).once.with(*%w(heros/1 heros/2)).and_return(jsons)
|
530
|
+
|
531
|
+
expect(HashWithMultipleAttributesLookUpOne.new.metrics).to eq(
|
532
|
+
[{:hero_id => 1, :hero_name => 'Rajini'},
|
533
|
+
{:hero_id => 2, :hero_name => nil}]
|
534
|
+
)
|
535
|
+
end
|
536
|
+
|
510
537
|
it 'should work for class methods' do
|
511
538
|
class SelfHelp
|
512
539
|
include Looksist
|
@@ -52,6 +52,24 @@ describe Looksist do
|
|
52
52
|
expect(e.nome).to eq('Rajini')
|
53
53
|
expect(e.age).to eq(16)
|
54
54
|
expect(e.to_json).to eq("{\"id\":1,\"nome\":\"Rajini\",\"age\":16}")
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should fetch attributes appropriately when plucking single attribute from a json key' do
|
58
|
+
module NonAliasSpecificLookup
|
59
|
+
class NoCacheEmployee
|
60
|
+
include Her::Model
|
61
|
+
use_api TEST_API
|
62
|
+
include Looksist
|
63
|
+
lookup :name, using: :id, as: {name: 'nome'}
|
64
|
+
def as_json(opts)
|
65
|
+
super(opts).merge(attributes)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
expect(@mock).to receive(:get).twice.times.with('ids/1').and_return({name: 'Rajini', age: 16}.to_json)
|
70
|
+
e = NonAliasSpecificLookup::NoCacheEmployee.new(id:1)
|
71
|
+
expect(e.nome).to eq('Rajini')
|
72
|
+
expect(e.to_json).to eq("{\"id\":1,\"nome\":\"Rajini\"}")
|
55
73
|
end
|
56
74
|
end
|
57
75
|
|
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.
|
4
|
+
version: 0.3.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RC
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-08-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|