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 +4 -4
- data/lib/shape/property_shaper.rb +9 -1
- data/lib/shape/version.rb +1 -1
- data/spec/property_shaper_spec.rb +66 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a41b7399f15f014baf2d9df24b00e30d8a929b8f
|
4
|
+
data.tar.gz: 8daea3cc9d1358297898270635c7cdeb0260ff56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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)
|
data/lib/shape/version.rb
CHANGED
@@ -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
|