upholsterer 1.1.0 → 1.2.0
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/Gemfile.lock +2 -2
- data/README.rdoc +0 -6
- data/lib/upholsterer/base.rb +15 -2
- data/lib/upholsterer/version.rb +1 -1
- data/spec/base_spec.rb +16 -2
- data/spec/support/expose_with_other_presenter.rb +4 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 303c16ed302b3ead74cc67760762121b90c0fade
|
4
|
+
data.tar.gz: a8bf3c053972fbdffb70ecedeb3952d6d5687401
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db657d479bf90b4f3681c57354b91791552020bc7f728cc896204651e486bb503a68cfcae8aa8a4c4fe7b4f8563beca9910a0ef4b4ff4285c6b82d8662b293aa
|
7
|
+
data.tar.gz: 03ec4859c46b7de076fcd733061a0058dbfc0294947b092f0369f25f269995a2e0dd2b8e31f88cd87ada83e904a0abf56adf75c3e085c9f050be1c5b04d46aea
|
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -62,12 +62,6 @@ If you're using Rails/Bundler or something like that, remember to override the <
|
|
62
62
|
|
63
63
|
gem "upholsterer", :require => "upholsterer/namespace"
|
64
64
|
|
65
|
-
== Maintainer
|
66
|
-
|
67
|
-
* Nando Vieira (http://nandovieira.com.br)
|
68
|
-
* Aleksandr Fomin (https://github.com/llxff)
|
69
|
-
* Gleb Sinyavsky (http://github.com/zhulik)
|
70
|
-
|
71
65
|
== License
|
72
66
|
|
73
67
|
(The MIT License)
|
data/lib/upholsterer/base.rb
CHANGED
@@ -48,6 +48,7 @@ module Upholsterer
|
|
48
48
|
attributes.each_value do |attr_name, options|
|
49
49
|
child.expose(attr_name, options)
|
50
50
|
end
|
51
|
+
child.do_not_use_prefixes! if do_not_use_prefixes?
|
51
52
|
end
|
52
53
|
|
53
54
|
# Store all attributes and options that have been exposed.
|
@@ -67,6 +68,14 @@ module Upholsterer
|
|
67
68
|
@attributes ||= {}
|
68
69
|
end
|
69
70
|
|
71
|
+
def self.do_not_use_prefixes!
|
72
|
+
@do_not_use_prefixes = true
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.do_not_use_prefixes?
|
76
|
+
@do_not_use_prefixes
|
77
|
+
end
|
78
|
+
|
70
79
|
# This method will return a presenter for each item of collection.
|
71
80
|
#
|
72
81
|
# users = UserPresenter.map(User.all)
|
@@ -102,7 +111,7 @@ module Upholsterer
|
|
102
111
|
options ||= {}
|
103
112
|
|
104
113
|
container = options.fetch(:with, nil)
|
105
|
-
method_prefix = container if options.fetch(:prefix,
|
114
|
+
method_prefix = container if options.fetch(:prefix, !do_not_use_prefixes?)
|
106
115
|
presenter = options.fetch(:presenter, nil)
|
107
116
|
|
108
117
|
if block_given? and container.present?
|
@@ -205,7 +214,11 @@ module Upholsterer
|
|
205
214
|
|
206
215
|
def decorate_with_presenter(value, presenter)
|
207
216
|
if value.present? and presenter
|
208
|
-
|
217
|
+
if value.is_a? Array
|
218
|
+
presenter.map(value)
|
219
|
+
else
|
220
|
+
presenter.new(value)
|
221
|
+
end
|
209
222
|
else
|
210
223
|
value
|
211
224
|
end
|
data/lib/upholsterer/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -165,6 +165,20 @@ describe Upholsterer::Base do
|
|
165
165
|
its([:user_name]) { should eql([:name, {with: :user}]) }
|
166
166
|
its([:post_title]) { should eql([:title, {with: :post}]) }
|
167
167
|
end
|
168
|
+
|
169
|
+
context 'do_not_use_prefixes' do
|
170
|
+
subject { presenter }
|
171
|
+
|
172
|
+
context 'without setting' do
|
173
|
+
its(:do_not_use_prefixes?) { should be_false }
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'with setting' do
|
177
|
+
before { CommentPresenter.do_not_use_prefixes! }
|
178
|
+
|
179
|
+
its(:do_not_use_prefixes?) { should be_true }
|
180
|
+
end
|
181
|
+
end
|
168
182
|
end
|
169
183
|
|
170
184
|
describe 'as json' do
|
@@ -227,11 +241,11 @@ describe Upholsterer::Base do
|
|
227
241
|
|
228
242
|
subject { ExposeWithOtherPresenter.new(user, comment) }
|
229
243
|
|
230
|
-
its(:
|
244
|
+
its(:name) { should eq 'Peter' }
|
231
245
|
|
232
246
|
specify { expect(subject.creator.name).to eq 'Steve' }
|
233
247
|
specify { expect(subject.creator.email).to eq 'steve@email.com' }
|
234
|
-
its(:to_json) { should be_json_with(
|
248
|
+
its(:to_json) { should be_json_with(name: 'Peter', creator: { name: 'Steve', email: 'steve@email.com'}) }
|
235
249
|
end
|
236
250
|
|
237
251
|
context 'with one subject' do
|
@@ -3,14 +3,16 @@ class SimplePresenter < Presenter
|
|
3
3
|
end
|
4
4
|
|
5
5
|
class ExposeWithOtherPresenter < Presenter
|
6
|
+
do_not_use_prefixes!
|
7
|
+
|
6
8
|
subjects :user, :comment
|
7
9
|
|
8
10
|
expose :name, with: :user
|
9
|
-
expose :user, presenter: SimplePresenter, with: :comment, as: :creator
|
11
|
+
expose :user, presenter: SimplePresenter, with: :comment, as: :creator
|
10
12
|
end
|
11
13
|
|
12
14
|
class ExposeWithOneSubjectPresenter < Presenter
|
13
15
|
expose :id
|
14
16
|
expose :user, presenter: SimplePresenter
|
15
17
|
expose :comment, presenter: SimplePresenter
|
16
|
-
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upholsterer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-12-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|