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 +4 -4
- data/README.md +3 -1
- data/lib/hash19/core_helpers.rb +6 -3
- data/lib/hash19/version.rb +1 -1
- data/spec/hash19/core_spec.rb +32 -16
- 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: 4724f0d19cf83a8c0f6b220195ea126152b4f09e
|
4
|
+
data.tar.gz: a85c570dc019daf1f0cfb487cd62e5ab72569a5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/hash19/core_helpers.rb
CHANGED
@@ -13,9 +13,12 @@ module Hash19
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def attribute(name, opts = {})
|
16
|
-
add_attributes(
|
17
|
-
|
18
|
-
|
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 = {})
|
data/lib/hash19/version.rb
CHANGED
data/spec/hash19/core_spec.rb
CHANGED
@@ -37,25 +37,41 @@ describe Hash19::Core do
|
|
37
37
|
context 'Single attribute and aliases' do
|
38
38
|
|
39
39
|
class Test2 < Testable
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
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.
|
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-
|
11
|
+
date: 2014-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|