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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/upholsterer/base.rb +9 -5
- data/lib/upholsterer/version.rb +1 -1
- data/spec/base_spec.rb +22 -0
- 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: c5a932e7f68ef2b1c1dd064ab0089f870a200217
|
4
|
+
data.tar.gz: b34e461cbec54c4bf1f9fcd04f981eae508a8093
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a8d9bea31d652f5caec931a57b8d341f1291772aa0a8dabafe0064b4cfedd8a4a73b0fd579ae86c85f94bc921c7c94e88b3344e7004579f568a6fbf0d2853ff
|
7
|
+
data.tar.gz: 8736fd3c961be81ec5c891a898a19b4564b7baa31a95834a8207257349a7dd25a1f4c912a7e20aeb34f0aabfb53412ffeb5742e821e59390948b03eed64df308
|
data/Gemfile.lock
CHANGED
data/lib/upholsterer/base.rb
CHANGED
@@ -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
|
210
|
-
|
211
|
-
|
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
|
|
data/lib/upholsterer/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -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.
|
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:
|
13
|
+
date: 2016-01-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|