frenetic 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
22
22
  gem.add_dependency 'addressable', '~> 2.2'
23
23
  gem.add_dependency 'patron', '~> 0.4.18'
24
24
 
25
- gem.add_development_dependency 'rspec', '~> 2.12.0'
26
- gem.add_development_dependency 'webmock', '~> 1.9.0'
25
+ gem.add_development_dependency 'rspec', '~> 2.13.0'
26
+ gem.add_development_dependency 'webmock', '~> 1.11.0'
27
27
  gem.add_development_dependency 'vcr', '~> 2.4.0'
28
28
  end
@@ -63,10 +63,20 @@ class Frenetic
63
63
  def build_associations( attributes )
64
64
  return unless attributes['_embedded']
65
65
 
66
- attributes['_embedded'].keys.each do |key|
66
+ namespace = self.class.to_s.deconstantize
67
+
68
+ attributes['_embedded'].each do |key, value|
67
69
  self.class.class_eval do
68
70
  attr_reader key.to_sym
69
71
  end
72
+
73
+ assoc_class = "#{namespace}::#{key.classify}"
74
+
75
+ if assoc_class = (assoc_class.constantize rescue nil)
76
+ value = assoc_class.new value
77
+ end
78
+
79
+ instance_variable_set "@#{key}", value
70
80
  end
71
81
  end
72
82
 
@@ -1,3 +1,3 @@
1
1
  class Frenetic
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
@@ -9,8 +9,8 @@ describe Frenetic::Resource do
9
9
  let(:description_stub) do
10
10
  Frenetic::HalJson::ResponseWrapper.new('resources' => {
11
11
  'schema' => {
12
- 'my_resource' => { 'properties' => { 'foo' => 'string' } },
13
- 'my_other_resource' => { 'properties' => {} }
12
+ 'my_resource' => { 'properties' => { 'foo' => 'string' } },
13
+ 'my_other_resource' => { 'properties' => { 'bar' => 'integer' } }
14
14
  } } )
15
15
  end
16
16
 
@@ -87,15 +87,31 @@ describe Frenetic::Resource do
87
87
  '_self' => { '_href' => 'bar' }
88
88
  },
89
89
  'foo' => 1,
90
- '_embedded' => {
91
- 'baz' => 'resource'
92
- }
90
+ '_embedded' => embed
93
91
  }
94
92
  end
95
93
 
96
94
  subject { resource_a }
97
95
 
98
- it { should respond_to(:baz) }
96
+ context 'that have a Resource representation' do
97
+ subject { super().my_other_resource }
98
+
99
+ let(:embed) do
100
+ { 'my_other_resource' => { 'bar' => 123 } }
101
+ end
102
+
103
+ its(:bar) { should == 123 }
104
+ end
105
+
106
+ context 'that do not have a Resource representation' do
107
+ subject { super().foo }
108
+
109
+ let(:embed) do
110
+ { 'foo' => { 'bar' => 'baz' } }
111
+ end
112
+
113
+ it { should include 'bar' => 'baz' }
114
+ end
99
115
  end
100
116
  end
101
117
 
@@ -149,5 +165,5 @@ describe Frenetic::Resource do
149
165
  expect { subject }.to raise_error(Frenetic::MissingAPIReference)
150
166
  end
151
167
  end
152
- end
168
+ end
153
169
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frenetic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-13 00:00:00.000000000 Z
12
+ date: 2013-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 2.12.0
117
+ version: 2.13.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ dependencies:
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: 2.12.0
125
+ version: 2.13.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: webmock
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -130,7 +130,7 @@ dependencies:
130
130
  requirements:
131
131
  - - ~>
132
132
  - !ruby/object:Gem::Version
133
- version: 1.9.0
133
+ version: 1.11.0
134
134
  type: :development
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
@@ -138,7 +138,7 @@ dependencies:
138
138
  requirements:
139
139
  - - ~>
140
140
  - !ruby/object:Gem::Version
141
- version: 1.9.0
141
+ version: 1.11.0
142
142
  - !ruby/object:Gem::Dependency
143
143
  name: vcr
144
144
  requirement: !ruby/object:Gem::Requirement