upholsterer 1.3.0 → 1.4.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/.travis.yml +9 -0
- data/Gemfile.lock +1 -1
- data/README.rdoc +1 -6
- data/lib/upholsterer/base.rb +4 -6
- data/lib/upholsterer/version.rb +1 -1
- data/spec/base_spec.rb +31 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88f0915e56e87ac3f84674452a38276d04fb7afe
|
4
|
+
data.tar.gz: 7f6250fc690066c2bfcfa4824f3ccff02b21cbe3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd5aa4746a69768107a55f6503245cc897172583b67f7e3893f213188809f3e61901e1c2a69873c716efbbb3b08d1225d97f4512f544b44cdeae8074eb09ca0e
|
7
|
+
data.tar.gz: 116a4360f2d79882f65eca474ff38adcf19e864f73b787d63914b6dfc7ce30440af0208d751dbb1ab97f892d6cb1f120c0511457ec0f8d57ad6a35331feb40b4
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@ Based on SimplePresenter (https://github.com/fnando/simple_presenter)
|
|
4
4
|
|
5
5
|
{<img src="https://codeclimate.com/github/llxff/upholsterer/badges/gpa.svg" />}[https://codeclimate.com/github/llxff/upholsterer]
|
6
6
|
{<img src="https://hakiri.io/github/llxff/upholsterer/master.svg" alt="security" />}[https://hakiri.io/github/llxff/upholsterer/master]
|
7
|
-
{<img src="https://travis-ci.org/
|
7
|
+
{<img src="https://travis-ci.org/RuntimeLLC/upholsterer.svg" />}[https://travis-ci.org/RuntimeLLC/upholsterer]
|
8
8
|
|
9
9
|
== Installation
|
10
10
|
|
@@ -41,11 +41,6 @@ If you want to to use <tt>*_url</tt> route methods, make sure you set the <tt>de
|
|
41
41
|
|
42
42
|
For additional usage, check the specs.
|
43
43
|
|
44
|
-
== TO-DO
|
45
|
-
|
46
|
-
* Recognize ActiveRecord objects and automatically expose attributes used by url and form helpers (like <tt>Model.model_name</tt>, <tt>Model#to_key</tt>, and <tt>Model#to_param</tt>).
|
47
|
-
* Override <tt>respond_to?</tt> to reflect exposed attributes.
|
48
|
-
|
49
44
|
== Troubleshooting
|
50
45
|
|
51
46
|
If you're having problems because already have a class/module called Presenter that is conflicting with this gem, you can require the namespace and inherit from <tt>Upholsterer::Base</tt>.
|
data/lib/upholsterer/base.rb
CHANGED
@@ -152,12 +152,10 @@ module Upholsterer
|
|
152
152
|
if block_given? and container.present?
|
153
153
|
delegate attr_name, to: wrapper_method, prefix: !!method_prefix
|
154
154
|
else
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
end
|
160
|
-
RUBY
|
155
|
+
define_method method_name do |&block|
|
156
|
+
value = proxy_message(container, attr_name, &block)
|
157
|
+
decorate_with_presenter(value, presenter)
|
158
|
+
end
|
161
159
|
end
|
162
160
|
end
|
163
161
|
end
|
data/lib/upholsterer/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -262,6 +262,37 @@ describe Upholsterer::Base do
|
|
262
262
|
|
263
263
|
its(:to_json) { should be_json_with(id: 1, user: { name: 'Peter', email: 'peter@email.com'}, comment: nil) }
|
264
264
|
end
|
265
|
+
|
266
|
+
context 'when presenter is anonym class' do
|
267
|
+
let(:anonym_presenter) do
|
268
|
+
Class.new(Presenter).tap do |presenter|
|
269
|
+
presenter.expose :name
|
270
|
+
presenter.expose :email
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
let(:presenter) do
|
275
|
+
Class.new(Presenter).tap do |presenter|
|
276
|
+
presenter.expose :id
|
277
|
+
presenter.expose :user, presenter: anonym_presenter
|
278
|
+
presenter.expose :comment, presenter: anonym_presenter
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
let(:user) { double name: 'Peter', email: 'peter@email.com' }
|
283
|
+
let(:post) { double user: user, comment: nil, id: 1}
|
284
|
+
|
285
|
+
subject { presenter.new(post) }
|
286
|
+
|
287
|
+
its(:id) { should eq 1 }
|
288
|
+
its(:comment) { should be_nil }
|
289
|
+
|
290
|
+
specify { expect(subject.user.name).to eq 'Peter' }
|
291
|
+
specify { expect(subject.user.email).to eq 'peter@email.com' }
|
292
|
+
|
293
|
+
its(:to_json) { should be_json_with(id: 1, user: { name: 'Peter', email: 'peter@email.com'}, comment: nil) }
|
294
|
+
its(:as_json) { should eq('id' => 1, 'user' => { 'name' => 'Peter', 'email' => 'peter@email.com'}, 'comment' => nil) }
|
295
|
+
end
|
265
296
|
end
|
266
297
|
|
267
298
|
describe 'custom subject' do
|
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.4.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: 2016-
|
13
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -78,6 +78,7 @@ extra_rdoc_files: []
|
|
78
78
|
files:
|
79
79
|
- ".gitignore"
|
80
80
|
- ".rspec"
|
81
|
+
- ".travis.yml"
|
81
82
|
- Gemfile
|
82
83
|
- Gemfile.lock
|
83
84
|
- README.rdoc
|