hash19 0.0.9 → 0.0.10

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: 24ad3203a40f611e4dd1377fec530dd5e84addcb
4
- data.tar.gz: 5a3248058a8423c5c91b9c4a83a69a0b3616ea78
3
+ metadata.gz: f058551acfa9dac0dc06b4974aad7bee1c35e1e2
4
+ data.tar.gz: 576d2bce4e5b1af1ed7b627a61111f8c65a2cf84
5
5
  SHA512:
6
- metadata.gz: 4aa7526345de10af58deaf60936dc9e0ed2badeffbb0e4d28bfb5bfd2547f766f5744123f2f992f39c22293e198ec0ee4f9576fbb875943f4e85d5dc5eded933
7
- data.tar.gz: bb06e9787149d039bec360a156d770a5ab355cbb700299aa509bad05cb4f643ca3189c0449ea8283c8bce217e0b87443c43d943b3216a544a633813822f9029d
6
+ metadata.gz: 4e2014f2d9e025517a1a4f5d720ffaf15ce707b7183597113605c94080a083e8c1640a10bdc10ff0e6174a77a97bf75c2b99a76091262750d269c69437f57945
7
+ data.tar.gz: a6c4c73367b57840c60395efcca0e37050d229e8a48e11b278d66f3191f4ab82e2469402ef4dfff88ec5f2524f894eca9f391516377afb24ef36bafec655fdeb
@@ -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.gsub(full_class_name.demodulize, assoc_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
@@ -1,3 +1,3 @@
1
1
  module Hash19
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
@@ -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
- to raise_error('Class:<Computer::Keyboard> not defined! Unable to resolve association:<keyboard>')
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
- {'error_id' => 404, 'desc' => 'not found'}])
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({"name" => 'Obi Wan Kenobi'})
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.9
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-21 00:00:00.000000000 Z
11
+ date: 2015-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler