hash19 0.0.6 → 0.0.7

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: 8d4abf9fa415283f0a656fd345f9bd33cc99bc59
4
- data.tar.gz: 99a02257f4412c560e9efa21b01c1152366de9db
3
+ metadata.gz: 4724f0d19cf83a8c0f6b220195ea126152b4f09e
4
+ data.tar.gz: a85c570dc019daf1f0cfb487cd62e5ab72569a5a
5
5
  SHA512:
6
- metadata.gz: f769a3aaaec08daeb22c90867935d858fd7fb31e3ad6d26cc81ca5be2acb90b1c39fc0ac7467a2a19cb9b0d23b54550d07928c26e0d096dff52d9cf6edf2dbad
7
- data.tar.gz: f88e1b86c8e5309d79e8d591114fab773bcacf6a647d5c01d6b8060606ba121f0a7761b998bf2c792c21457cfe323dfc4930da2a9901a59fa53bc5576c63c665
6
+ metadata.gz: cb8d181a696c67a437691df48030c4c203487d396c3be66ae119ea960191f8d29d6e68cc5135a67d4943e3f836ca181f625e7678dc716e37e9c500bf2b61f022
7
+ data.tar.gz: 80bcb0601b44bfcfefa314f4eeac3577620123828d29187c344795ca67678e94e8bd1543b36626b3d0464662d08eebdcfd826cce466164314a6ca69b646bf992
data/README.md CHANGED
@@ -186,7 +186,9 @@ super_heroes.to_h #[{'name' => 'iron man', 'power' => 'none', 'weapon' => {'name
186
186
  #{'name' => 'hulk', 'power' => 'bulk', 'weapon' => {'name' => 'hands', 'id' => 3}}
187
187
  ```
188
188
 
189
- Note that `injection` always overrides the association trigger sinces the former is eager loaded and latter is lazy loaded thus avoiding the `N+1` calls.
189
+ Note that `injection` always overrides the association trigger sinces the former is eager loaded and latter is lazy loaded thus avoiding the `N+1` calls.
190
+
191
+ One other important thing to remember is that all the injections will happen in parallel. Hash19 uses [eldritch](https://github.com/beraboris/eldritch) gem to trigger multiple injections concurrently.
190
192
 
191
193
  Please refer to the [tests](https://github.com/rcdexta/hash19/tree/master/spec/hash19) for more examples and documentation.
192
194
 
@@ -13,9 +13,12 @@ module Hash19
13
13
  end
14
14
 
15
15
  def attribute(name, opts = {})
16
- add_attributes(opts[:key] || name)
17
- @aliases ||= {}
18
- @aliases[opts[:key]] = name if opts.has_key?(:key)
16
+ add_attributes(name)
17
+ if opts.has_key?(:key)
18
+ @aliases ||= {}
19
+ @aliases[opts[:key]] = name
20
+ add_attributes(opts[:key])
21
+ end
19
22
  end
20
23
 
21
24
  def has_one(name, opts = {})
@@ -1,3 +1,3 @@
1
1
  module Hash19
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -37,25 +37,41 @@ describe Hash19::Core do
37
37
  context 'Single attribute and aliases' do
38
38
 
39
39
  class Test2 < Testable
40
- attributes :a, :b, :c
41
- attribute :fake, key: :actual
42
- attribute :d
43
- end
44
-
45
- it 'should be able to assign attributes based on alias' do
46
- test = Test2.new("actual" => 1, "d" => 2)
47
- expect(test.to_h).to eq('fake' => 1, "d" => 2)
48
- end
40
+ attributes :a, :b, :c
41
+ attribute :fake, key: :actual
42
+ attribute :d
43
+ end
44
+
45
+ it 'should be able to assign attributes based on alias' do
46
+ test = Test2.new("actual" => 1, "d" => 2)
47
+ expect(test.to_h).to eq('fake' => 1, "d" => 2)
48
+ end
49
+
50
+ it 'should be able to use both attribute and attributes constructs' do
51
+ test = Test2.new(actual: 1, a: 2, d: 3)
52
+ expect(test.to_h).to eq('fake' => 1, 'a' => 2, 'd' => 3)
53
+ end
49
54
 
50
- it 'should be able to use both attribute and attributes constructs' do
51
- test = Test2.new(actual: 1, a: 2, d: 3)
52
- expect(test.to_h).to eq('fake' => 1, 'a' => 2, 'd' => 3)
55
+ it 'should ignore alias if key not present' do
56
+ test = Test2.new(a: 2)
57
+ expect(test.to_h).to eq('a' => 2)
58
+ end
53
59
  end
54
60
 
55
- it 'should ignore alias if key not present' do
56
- test = Test2.new(a: 2)
57
- expect(test.to_h).to eq('a' => 2)
61
+ context 'alias and key play' do
62
+ class AliasPlay < Testable
63
+ attribute :original, key: :alias
64
+ end
65
+
66
+ it 'should be able to resolve alias' do
67
+ ap = AliasPlay.new('alias' => 1)
68
+ expect(ap.to_h).to eq('original' => 1)
69
+ end
70
+
71
+ it 'should be able to resolve original if alias not found >:)' do
72
+ ap = AliasPlay.new('original' => 1)
73
+ expect(ap.to_h).to eq('original' => 1)
74
+ end
58
75
  end
59
- end
60
76
 
61
77
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash19
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - RC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-15 00:00:00.000000000 Z
11
+ date: 2014-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler