looksist 0.3.11 → 0.3.12

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: 69c773e23a25636e39c6a9fa5d509ede5915cc2e
4
- data.tar.gz: d2dcfa3496a4dc19519bf7472ed0250948fe8870
3
+ metadata.gz: 9f63a1c36d1bac556df87d59b84e56d3cb912864
4
+ data.tar.gz: bda04de8e57710e3aeb2c7f48b8b75b53cf947a4
5
5
  SHA512:
6
- metadata.gz: df141569de0cf50b2597916fa0d3a4f210c7e9480537c234355be7619fc0e00bbf5f09c35cde13362a77d0b5a872b44010aef21188c78001997f87672494ac4e
7
- data.tar.gz: ef61fb2dc42865334b6ef5fe06efa762f4d40ee9f997f0b6573477624c785d2227f1a2a85b24c6e4e37a6af4be24bfd7126e197f8dea99decc624308bcd7ca7a
6
+ metadata.gz: 86f43387109482d62aec666accbb5b68bb10c25e7ba30d6eead747aa9970f4bf5f0d2e24f64126af2dec368834db791b7f590983c8b4ec88892526d1828f4018
7
+ data.tar.gz: 6a1c54940cf6592d5eac3358f755838a3b64222bb46a4a2bedb3151cd4c831926895916d94ef5f8800cb220ece2bd77ab3391d8cd1b373ffadf72b849cb66d57
@@ -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
@@ -161,7 +161,12 @@ module Looksist
161
161
  end
162
162
  else
163
163
  alias_method = find_alias(as, populate)
164
- elt[alias_method] = values[elt.with_indifferent_access[using]]
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
 
@@ -1,3 +1,3 @@
1
1
  module Lookist
2
- VERSION = '0.3.11'
2
+ VERSION = '0.3.12'
3
3
  end
@@ -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.11
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: 2014-12-03 00:00:00.000000000 Z
12
+ date: 2015-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler