upholsterer 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 303c16ed302b3ead74cc67760762121b90c0fade
4
- data.tar.gz: a8bf3c053972fbdffb70ecedeb3952d6d5687401
3
+ metadata.gz: c5a932e7f68ef2b1c1dd064ab0089f870a200217
4
+ data.tar.gz: b34e461cbec54c4bf1f9fcd04f981eae508a8093
5
5
  SHA512:
6
- metadata.gz: db657d479bf90b4f3681c57354b91791552020bc7f728cc896204651e486bb503a68cfcae8aa8a4c4fe7b4f8563beca9910a0ef4b4ff4285c6b82d8662b293aa
7
- data.tar.gz: 03ec4859c46b7de076fcd733061a0058dbfc0294947b092f0369f25f269995a2e0dd2b8e31f88cd87ada83e904a0abf56adf75c3e085c9f050be1c5b04d46aea
6
+ metadata.gz: 7a8d9bea31d652f5caec931a57b8d341f1291772aa0a8dabafe0064b4cfedd8a4a73b0fd579ae86c85f94bc921c7c94e88b3344e7004579f568a6fbf0d2853ff
7
+ data.tar.gz: 8736fd3c961be81ec5c891a898a19b4564b7baa31a95834a8207257349a7dd25a1f4c912a7e20aeb34f0aabfb53412ffeb5742e821e59390948b03eed64df308
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- upholsterer (1.2.0)
4
+ upholsterer (1.3.0)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -131,8 +131,6 @@ module Upholsterer
131
131
  instance_variable_set(wrapper_instance_variable, wrapper)
132
132
  end
133
133
 
134
-
135
-
136
134
  value = instance_variable_get(wrapper_instance_variable)
137
135
  decorate_with_presenter(value, presenter)
138
136
  end
@@ -205,10 +203,16 @@ module Upholsterer
205
203
  end
206
204
 
207
205
  private
206
+
208
207
  def proxy_message(subject_name, method, &block)
209
- subject_name ||= self.class.subjects.first
210
- subject = instance_variable_get("@#{subject_name}")
211
- subject = instance_variable_get("@#{self.class.subjects.first}").__send__(subject_name) unless subject || self.class.subjects.include?(subject_name)
208
+ if subject_name.blank? # expose :id
209
+ subject = send(self.class.subjects.first)
210
+ elsif self.class.subjects.include?(subject_name) # expose :id, with: :user, when :user is one of subjects or custom getter
211
+ subject = send(subject_name)
212
+ else
213
+ subject = send(self.class.subjects.first).send(subject_name)# expose :id, with: :user
214
+ end
215
+
212
216
  subject.respond_to?(method) ? subject.__send__(method, &block) : nil
213
217
  end
214
218
 
@@ -1,7 +1,7 @@
1
1
  module Upholsterer
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 2
4
+ MINOR = 3
5
5
  PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
@@ -263,4 +263,26 @@ describe Upholsterer::Base do
263
263
  its(:to_json) { should be_json_with(id: 1, user: { name: 'Peter', email: 'peter@email.com'}, comment: nil) }
264
264
  end
265
265
  end
266
+
267
+ describe 'custom subject' do
268
+ let(:presenter) do
269
+ Class.new(Presenter) do
270
+ subjects :message, :user
271
+
272
+ expose :id
273
+ expose :name, with: :user
274
+
275
+ private
276
+
277
+ def user
278
+ message.recipient.user
279
+ end
280
+ end
281
+ end
282
+
283
+ subject { presenter.new(double(id: 1, recipient: double(user: double(name: 'Tom')))) }
284
+
285
+ its(:id) { should eq 1 }
286
+ its(:user_name) { should eq 'Tom' }
287
+ end
266
288
  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.2.0
4
+ version: 1.3.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-12-17 00:00:00.000000000 Z
13
+ date: 2016-01-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake