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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5a932e7f68ef2b1c1dd064ab0089f870a200217
4
- data.tar.gz: b34e461cbec54c4bf1f9fcd04f981eae508a8093
3
+ metadata.gz: 88f0915e56e87ac3f84674452a38276d04fb7afe
4
+ data.tar.gz: 7f6250fc690066c2bfcfa4824f3ccff02b21cbe3
5
5
  SHA512:
6
- metadata.gz: 7a8d9bea31d652f5caec931a57b8d341f1291772aa0a8dabafe0064b4cfedd8a4a73b0fd579ae86c85f94bc921c7c94e88b3344e7004579f568a6fbf0d2853ff
7
- data.tar.gz: 8736fd3c961be81ec5c891a898a19b4564b7baa31a95834a8207257349a7dd25a1f4c912a7e20aeb34f0aabfb53412ffeb5742e821e59390948b03eed64df308
6
+ metadata.gz: fd5aa4746a69768107a55f6503245cc897172583b67f7e3893f213188809f3e61901e1c2a69873c716efbbb3b08d1225d97f4512f544b44cdeae8074eb09ca0e
7
+ data.tar.gz: 116a4360f2d79882f65eca474ff38adcf19e864f73b787d63914b6dfc7ce30440af0208d751dbb1ab97f892d6cb1f120c0511457ec0f8d57ad6a35331feb40b4
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.0.0
7
+ - 2.1
8
+ - 2.2
9
+ - 2.2.3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- upholsterer (1.3.0)
4
+ upholsterer (1.4.0)
5
5
  activesupport
6
6
 
7
7
  GEM
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/llxff/upholsterer.svg" />}[https://travis-ci.org/llxff/upholsterer]
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>.
@@ -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
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
156
- def #{method_name}(&block)
157
- value = proxy_message(#{container.inspect}, "#{attr_name}", &block)
158
- decorate_with_presenter(value, #{ presenter.inspect })
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
@@ -1,7 +1,7 @@
1
1
  module Upholsterer
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 3
4
+ MINOR = 4
5
5
  PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
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.3.0
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-01-27 00:00:00.000000000 Z
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