bourgeois 0.1.5 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/bourgeois/version.rb +1 -1
- data/lib/bourgeois/view_helper.rb +10 -6
- data/spec/bourgeois/view_helper_spec.rb +31 -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: f2bc10e6f30ee29a0b8bb2fd612ef97f8f67cf49
|
4
|
+
data.tar.gz: c31c4dba94b71fcf88b06523325523644863f633
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f635a2839bf1ad9d0a3a1b2825103675cd284062b080a4eb774df234fbbf9803333f2ba27d0706b1cbbaba11dc618ea2c8849c5a6c699ae7f911b75706dd8b1
|
7
|
+
data.tar.gz: 56923d9ed6669f71491150fb08bd65885e9363cb57e2d62f057ab9f48ba8c2dd0d736d012e840fcbcf7932dc23f414b6f02cfd67f084c4071eee460a0b0f4783
|
data/README.md
CHANGED
@@ -73,7 +73,7 @@ class UserPresenter < Bourgeois::Presenter
|
|
73
73
|
helper :with_profile, if: -> { profile.present? && profile.public? }
|
74
74
|
end
|
75
75
|
|
76
|
-
User.first.
|
76
|
+
User.first.profile = Profile.create(public: true, title: 'Foo', description: 'Bar')
|
77
77
|
```
|
78
78
|
|
79
79
|
```erb
|
data/lib/bourgeois/version.rb
CHANGED
@@ -11,15 +11,19 @@ module Bourgeois
|
|
11
11
|
return object.map { |o| present(o, klass, &blk) } if object.respond_to?(:to_a)
|
12
12
|
|
13
13
|
if klass.blank?
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
if object.is_a?(Bourgeois::Presenter)
|
15
|
+
presenter = object
|
16
|
+
else
|
17
|
+
begin
|
18
|
+
klass_name = "#{object.class}Presenter"
|
19
|
+
klass = klass_name.constantize
|
20
|
+
rescue ::NameError
|
21
|
+
raise UnknownPresenter.new(klass_name)
|
22
|
+
end
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
22
|
-
presenter
|
26
|
+
presenter ||= klass.new(object, self)
|
23
27
|
yield presenter if block_given?
|
24
28
|
|
25
29
|
presenter
|
@@ -30,6 +30,23 @@ describe Bourgeois::ViewHelper do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
context 'on a single already-presented resource' do
|
34
|
+
let(:user) { User.new first_name: 'Patrick', last_name: 'Bourgeois' }
|
35
|
+
let(:presenter) { UserPresenter.new(user) }
|
36
|
+
|
37
|
+
context 'without a block' do
|
38
|
+
it { expect(view.present(presenter).formatted_name).to eql 'Patrick Bourgeois' }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with a block' do
|
42
|
+
specify do
|
43
|
+
view.present(presenter) do |u|
|
44
|
+
expect(u.formatted_name).to eql 'Patrick Bourgeois'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
33
50
|
context 'on a collection of resources' do
|
34
51
|
let(:user1) { User.new first_name: 'Patrick', last_name: 'Bourgeois' }
|
35
52
|
let(:user2) { User.new first_name: 'Francois', last_name: 'Jean' }
|
@@ -44,6 +61,20 @@ describe Bourgeois::ViewHelper do
|
|
44
61
|
end
|
45
62
|
end
|
46
63
|
|
64
|
+
context 'on a collection of already-presented resources' do
|
65
|
+
let(:user1) { User.new first_name: 'Patrick', last_name: 'Bourgeois' }
|
66
|
+
let(:user2) { User.new first_name: 'Francois', last_name: 'Jean' }
|
67
|
+
let(:user3) { User.new first_name: 'Alain', last_name: 'Lapointe' }
|
68
|
+
let(:users) { [UserPresenter.new(user1), UserPresenter.new(user2), UserPresenter.new(user3)] }
|
69
|
+
|
70
|
+
specify do
|
71
|
+
output = []
|
72
|
+
view.present(users) { |u| output << u.formatted_name }
|
73
|
+
|
74
|
+
expect(output).to eql ['Patrick Bourgeois', 'Francois Jean', 'Alain Lapointe']
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
47
78
|
context 'on a resource without a defined presenter class' do
|
48
79
|
before do
|
49
80
|
class Project < OpenStruct; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bourgeois
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rémi Prévost
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|