dry-view 0.5.1 → 0.5.2
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/CHANGELOG.md +8 -0
- data/lib/dry/view/part.rb +12 -7
- data/lib/dry/view/version.rb +1 -1
- data/spec/integration/part/decorated_attributes_spec.rb +41 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d739724ab980eb210e9f651c78b3cbdf59e28c597e149b05d936f49a89f9d74f
|
4
|
+
data.tar.gz: 23604cb777111c1711b09fd1da0b98f18840872d6c03f6867257eb42b3b3d755
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e66915108ff44c6e164459e30d3bcff67324b50dbd52bd853e1802bcbbefe824b440fc5e6e018033778f5d80717b8b61da1eaaf50071cad6ec9f3da154b15f8
|
7
|
+
data.tar.gz: c587910c53a1d229533740204875a99b480e232b8a8fb397775dc234d33cdda60b42095800ba7c16d3c4d181a64d9f7bab909e202684f7d8e192222a7d9cb650
|
data/CHANGELOG.md
CHANGED
data/lib/dry/view/part.rb
CHANGED
@@ -90,13 +90,18 @@ module Dry
|
|
90
90
|
|
91
91
|
def _resolve_decorated_attribute(name)
|
92
92
|
_decorated_attributes.fetch(name) {
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
93
|
+
attribute = _value.__send__(name)
|
94
|
+
|
95
|
+
_decorated_attributes[name] =
|
96
|
+
if attribute # Decorate truthy attributes only
|
97
|
+
_decorator.(
|
98
|
+
name,
|
99
|
+
attribute,
|
100
|
+
renderer: _renderer,
|
101
|
+
context: _context,
|
102
|
+
**self.class.decorated_attributes[name],
|
103
|
+
)
|
104
|
+
end
|
100
105
|
}
|
101
106
|
end
|
102
107
|
end
|
data/lib/dry/view/version.rb
CHANGED
@@ -32,10 +32,14 @@ RSpec.describe 'Part / Decorated attributes' do
|
|
32
32
|
end
|
33
33
|
}
|
34
34
|
|
35
|
+
let (:author) {
|
36
|
+
author_class.new(name: 'Jane Doe')
|
37
|
+
}
|
38
|
+
|
35
39
|
let(:article) {
|
36
40
|
article_class.new(
|
37
41
|
title: 'Hello world',
|
38
|
-
author:
|
42
|
+
author: author,
|
39
43
|
comments: [
|
40
44
|
comment_class.new(author: author_class.new(name: 'Sue Smith'), body: 'Great article')
|
41
45
|
]
|
@@ -59,10 +63,18 @@ RSpec.describe 'Part / Decorated attributes' do
|
|
59
63
|
end
|
60
64
|
}
|
61
65
|
|
62
|
-
it 'decorates
|
66
|
+
it 'decorates attributes with the standard Dry::View::Part class' do
|
63
67
|
expect(article_part.author).to be_a Dry::View::Part
|
64
68
|
expect(article_part.comments[0]).to be_a Dry::View::Part
|
65
69
|
end
|
70
|
+
|
71
|
+
context 'falsey values' do
|
72
|
+
let(:author) { nil }
|
73
|
+
|
74
|
+
it 'does not decorate the attributes' do
|
75
|
+
expect(article_part.author).to be_nil
|
76
|
+
end
|
77
|
+
end
|
66
78
|
end
|
67
79
|
|
68
80
|
describe 'single declaration' do
|
@@ -72,10 +84,18 @@ RSpec.describe 'Part / Decorated attributes' do
|
|
72
84
|
end
|
73
85
|
}
|
74
86
|
|
75
|
-
it 'decorates
|
87
|
+
it 'decorates attributes with the standard Dry::View::Part class' do
|
76
88
|
expect(article_part.author).to be_a Dry::View::Part
|
77
89
|
expect(article_part.comments[0]).to be_a Dry::View::Part
|
78
90
|
end
|
91
|
+
|
92
|
+
context 'falsey values' do
|
93
|
+
let(:author) { nil }
|
94
|
+
|
95
|
+
it 'does not decorate the attributes' do
|
96
|
+
expect(article_part.author).to be_nil
|
97
|
+
end
|
98
|
+
end
|
79
99
|
end
|
80
100
|
end
|
81
101
|
|
@@ -97,10 +117,18 @@ RSpec.describe 'Part / Decorated attributes' do
|
|
97
117
|
end
|
98
118
|
}
|
99
119
|
|
100
|
-
it 'deorates
|
120
|
+
it 'deorates attributes with the specified part class' do
|
101
121
|
expect(article_part.author).to be_a Test::AuthorPart
|
102
122
|
expect(article_part.comments[0]).to be_a Test::CommentPart
|
103
123
|
end
|
124
|
+
|
125
|
+
context 'falsey values' do
|
126
|
+
let(:author) { nil }
|
127
|
+
|
128
|
+
it 'does not decorate the attributes' do
|
129
|
+
expect(article_part.author).to be_nil
|
130
|
+
end
|
131
|
+
end
|
104
132
|
end
|
105
133
|
end
|
106
134
|
|
@@ -148,10 +176,18 @@ RSpec.describe 'Part / Decorated attributes' do
|
|
148
176
|
end
|
149
177
|
end
|
150
178
|
|
151
|
-
it 'deorates
|
179
|
+
it 'deorates attributes using the custom decorator' do
|
152
180
|
expect(article_part.author).to be_a Test::AuthorPart
|
153
181
|
expect(article_part.comments[0]).to be_a Test::CommentPart
|
154
182
|
expect(article_part.comments[0].author).to be_a Test::AuthorPart
|
155
183
|
end
|
184
|
+
|
185
|
+
context 'falsey values' do
|
186
|
+
let(:author) { nil }
|
187
|
+
|
188
|
+
it 'does not decorate the attributes' do
|
189
|
+
expect(article_part.author).to be_nil
|
190
|
+
end
|
191
|
+
end
|
156
192
|
end
|
157
193
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tilt
|