showcase 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/showcase/presenter.rb +14 -12
- data/lib/showcase/version.rb +1 -1
- data/spec/fixtures.rb +11 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97986f4c8b78d2999f33ee25f1f966d72116eddb
|
4
|
+
data.tar.gz: d432bc5a7758a657aadea20c3b7212839cc846eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 389db1473fe7e4fbfefe82e519a0191b9bda00b0fbb5f01d10cdcdb1284c3abb7bb4f19588082a579a161eff9ecabf984a16352bc8f37532c38fd147243fcbdf
|
7
|
+
data.tar.gz: bca7eb64152e096c1977b5043bd37340f004aa9b7000c3c01c86bdfe4d891362da99dca621bd2edc48f8b1ef170d5545068008f9f4b15ab58143ca999e00b60e
|
data/lib/showcase/presenter.rb
CHANGED
@@ -31,27 +31,29 @@ module Showcase
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.presents(*args)
|
34
|
-
|
35
|
-
options.assert_valid_keys(:with)
|
36
|
-
presenter_klass = options.fetch(:with, nil)
|
37
|
-
|
38
|
-
args.each do |attr|
|
39
|
-
define_method attr do
|
40
|
-
present(object.send(attr), presenter_klass, view_context)
|
41
|
-
end
|
42
|
-
end
|
34
|
+
wrap_methods(args, :present)
|
43
35
|
end
|
44
36
|
|
45
37
|
def self.presents_collection(*args)
|
38
|
+
wrap_methods(args, :present_collection)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def self.wrap_methods(args, method)
|
46
44
|
options = args.extract_options!
|
47
45
|
options.assert_valid_keys(:with)
|
48
46
|
presenter_klass = options.fetch(:with, nil)
|
49
47
|
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
methods_module = Module.new do
|
49
|
+
args.each do |attr|
|
50
|
+
define_method attr do
|
51
|
+
send(method, object.send(attr), presenter_klass, view_context)
|
52
|
+
end
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
include(methods_module)
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
data/lib/showcase/version.rb
CHANGED
data/spec/fixtures.rb
CHANGED
@@ -38,11 +38,16 @@ end
|
|
38
38
|
class ProjectPresenter < Showcase::Presenter
|
39
39
|
presents :owner, with: AdminPresenter
|
40
40
|
presents_collection :collaborators
|
41
|
+
presents :owner_child
|
41
42
|
|
42
43
|
def name
|
43
44
|
"Presented #{object.name}"
|
44
45
|
end
|
45
46
|
|
47
|
+
def owner
|
48
|
+
super
|
49
|
+
end
|
50
|
+
|
46
51
|
def bold_name
|
47
52
|
h.bold(object.name)
|
48
53
|
end
|
@@ -60,3 +65,9 @@ class Context
|
|
60
65
|
end
|
61
66
|
end
|
62
67
|
|
68
|
+
class Shop
|
69
|
+
def owner
|
70
|
+
Person.new("Stefano Verna")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|