hash19 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hash19/resolvers.rb +6 -1
- data/lib/hash19/version.rb +1 -1
- data/spec/hash19/associations_spec.rb +19 -3
- 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: f058551acfa9dac0dc06b4974aad7bee1c35e1e2
|
4
|
+
data.tar.gz: 576d2bce4e5b1af1ed7b627a61111f8c65a2cf84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e2014f2d9e025517a1a4f5d720ffaf15ce707b7183597113605c94080a083e8c1640a10bdc10ff0e6174a77a97bf75c2b99a76091262750d269c69437f57945
|
7
|
+
data.tar.gz: a6c4c73367b57840c60395efcca0e37050d229e8a48e11b278d66f3191f4ab82e2469402ef4dfff88ec5f2524f894eca9f391516377afb24ef36bafec655fdeb
|
data/lib/hash19/resolvers.rb
CHANGED
@@ -50,7 +50,7 @@ module Hash19
|
|
50
50
|
|
51
51
|
def resolve_class(assoc_name)
|
52
52
|
full_class_name = self.class.name
|
53
|
-
new_class = full_class_name
|
53
|
+
new_class = construct_association_class full_class_name, assoc_name
|
54
54
|
new_class.split('::').inject(Object) do |mod, class_name|
|
55
55
|
begin
|
56
56
|
mod.const_get(class_name)
|
@@ -62,6 +62,11 @@ module Hash19
|
|
62
62
|
|
63
63
|
private
|
64
64
|
|
65
|
+
def construct_association_class(parent, association)
|
66
|
+
*modules, class_name = parent.split('::')
|
67
|
+
(modules + [association]).join('::')
|
68
|
+
end
|
69
|
+
|
65
70
|
def async_injections
|
66
71
|
self.class.injections.select { |e| e[:async].nil? }
|
67
72
|
end
|
data/lib/hash19/version.rb
CHANGED
@@ -30,7 +30,7 @@ describe 'Associations' do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
expect { Computer::Laptop.new(model: 'MacBook Pro', year: 2013, keyboard: {keys: 101}) }.
|
33
|
-
|
33
|
+
to raise_error('Class:<Computer::Keyboard> not defined! Unable to resolve association:<keyboard>')
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'should support alternate key in payload for has_one' do
|
@@ -144,7 +144,7 @@ describe 'Associations' do
|
|
144
144
|
it 'should be able to call the trigger on has_one association' do
|
145
145
|
packet = UDPPacket.new(code: 500, error_id: 500)
|
146
146
|
expect(packet.to_h).to eq('code' => 500, 'error_id' => 500, 'all_errors' => [{'error_id' => 500, 'desc' => 'fatal error'},
|
147
|
-
|
147
|
+
{'error_id' => 404, 'desc' => 'not found'}])
|
148
148
|
end
|
149
149
|
|
150
150
|
end
|
@@ -157,7 +157,23 @@ describe 'Associations' do
|
|
157
157
|
end
|
158
158
|
|
159
159
|
jedi = Jedi.new(name: 'Obi Wan Kenobi')
|
160
|
-
expect(jedi.to_h).to eq({
|
160
|
+
expect(jedi.to_h).to eq({'name' => 'Obi Wan Kenobi'})
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'module and class with same name' do
|
165
|
+
module SecretAgentService
|
166
|
+
class SecretAgent < Testable
|
167
|
+
attributes :code
|
168
|
+
has_one :agency
|
169
|
+
end
|
170
|
+
class Agency < Testable
|
171
|
+
attributes :name
|
172
|
+
end
|
173
|
+
end
|
174
|
+
it 'should resolve class when association class and containing module have same name' do
|
175
|
+
mi6 = SecretAgentService::SecretAgent.new({code: '007', agency: {name: 'MI6'}})
|
176
|
+
expect(mi6.to_h).to eq({'code' => '007', 'agency' => {'name' => 'MI6'}})
|
161
177
|
end
|
162
178
|
end
|
163
179
|
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RC
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|