shape 0.0.1 → 0.1.1

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: 7721ae7dec761e6fc7df7c801c2fa4e2176d07d4
4
- data.tar.gz: ccbbc447f0038018e40a1f1e75d8e2c4444a5562
3
+ metadata.gz: a41b7399f15f014baf2d9df24b00e30d8a929b8f
4
+ data.tar.gz: 8daea3cc9d1358297898270635c7cdeb0260ff56
5
5
  SHA512:
6
- metadata.gz: 878acd9eab21ba6c2732285de0b2810f71038b801764060ccf29c5eee1222b8e4c7cf5f43cfa80423d90b5d9d40a74ec4d3be0ab64697576fb2e1e4d24698c72
7
- data.tar.gz: aa47f8d4ac3e7bcd5e08332f111d7b706e63810d70ea8bc86775b9279da5da02e13c22bdcb6f23802b4e525c074085ac1b9b76b3b7feca0d4df0392a646b2288
6
+ metadata.gz: c2546057236cead9af6c180326017935931d2153e8787981fe268272d9bfe1e8efa55af7d1e53ac07dd3f9b0707500902f119c9739ca465b740b02bba26df000
7
+ data.tar.gz: c1f72e78cb936d51ef14a0899247d5af3c1de5af1594a2ec4122f50fa3ed1668bd5bfff2fc3238fb351d6bc8f905c5c236f74dfe6a8c06e7286f4514b25d477b
@@ -1,7 +1,7 @@
1
1
  module Shape
2
2
  # = Property Shaper
3
3
  # Keeps track of property info and context
4
- # when shaping shaper views.
4
+ # when shaping views.
5
5
  #
6
6
  # We'll use the PropertyShaper objects
7
7
  # later to recursively build the data.
@@ -47,6 +47,14 @@ module Shape
47
47
  end
48
48
  end
49
49
 
50
+ def with(&block)
51
+ options[:with] = Class.new do
52
+ include Shape
53
+ instance_eval(&block)
54
+ end
55
+ define_accessor(name, options[:from] || name)
56
+ end
57
+
50
58
  protected
51
59
 
52
60
  def define_accessor(name, source_name)
@@ -1,3 +1,3 @@
1
1
  module Shape
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -134,6 +134,72 @@ describe Shape::PropertyShaper do
134
134
 
135
135
  end
136
136
 
137
+ context 'and a Shape decorator with property using a with block' do
138
+
139
+ before do
140
+ stub_const('ChildDecorator', Class.new do
141
+ include Shape::Base
142
+ property :name
143
+ end)
144
+
145
+ stub_const('MockDecorator', Class.new do
146
+ include Shape::Base
147
+ property :children do
148
+ with do
149
+ property :name
150
+ end
151
+ end
152
+ end)
153
+
154
+ end
155
+
156
+ context 'when shaped by the decorator' do
157
+
158
+ subject {
159
+ MockDecorator.new(source)
160
+ }
161
+
162
+ it 'exposes and shapes each child element of the property with the provided decorator' do
163
+ expect(subject.children.map(&:name)).to eq(['Jimmy Smith', 'Jane Smith'])
164
+ end
165
+
166
+ end
167
+
168
+ end
169
+
170
+ context 'and a Shape decorator with property using from option and a with block' do
171
+
172
+ before do
173
+ stub_const('ChildDecorator', Class.new do
174
+ include Shape::Base
175
+ property :name
176
+ end)
177
+
178
+ stub_const('MockDecorator', Class.new do
179
+ include Shape::Base
180
+ property :dependents, from: :children do
181
+ with do
182
+ property :name
183
+ end
184
+ end
185
+ end)
186
+
187
+ end
188
+
189
+ context 'when shaped by the decorator' do
190
+
191
+ subject {
192
+ MockDecorator.new(source)
193
+ }
194
+
195
+ it 'exposes and shapes each child element of the property with the provided decorator' do
196
+ expect(subject.dependents.map(&:name)).to eq(['Jimmy Smith', 'Jane Smith'])
197
+ end
198
+
199
+ end
200
+
201
+ end
202
+
137
203
  end
138
204
 
139
205
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Curry