presenter_rails 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/presenter_rails/presenter.rb +20 -21
- 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: 7369b035085593e7c248402cfc1fba20a1dfb15a
|
4
|
+
data.tar.gz: 0e785985be1e307d9d88ee6159521fab37b6fdd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8750fc439086bce43b647378fab34d1f2205a149574f036a3333ab2f7084090710ca431744618d1492a9b56064df1d043b7fca7001192aa17208cefd1c7463ac
|
7
|
+
data.tar.gz: 51bd7a3ba559607f64f9667a07cc54da40415abb49b862d105e038cbf153f4f3790ae76f99b5c10bb729b4427a689a697cfb4811f365daa0dd6060f2d2ae356f
|
@@ -4,21 +4,23 @@ module PresenterRails
|
|
4
4
|
include SimpleMemoizer
|
5
5
|
|
6
6
|
module ClassMethods
|
7
|
-
def present(*methods)
|
8
|
-
methods.flatten!
|
9
|
-
presenter_methods = *Presenter.presenter_method_names(methods)
|
10
|
-
enforce_private_methods!(presenter_methods)
|
11
7
|
|
12
|
-
|
13
|
-
|
8
|
+
# Can take a list of presenter methods, or a name and block for a presenter method
|
9
|
+
def present(*methods, &block)
|
10
|
+
presenter_methods = methods.map {|name| Presenter.method_name_for(name) }
|
11
|
+
define_presenter_method!(presenter_methods, &block) if block_given?
|
12
|
+
|
13
|
+
expose_presenter *methods
|
14
|
+
memoize *presenter_methods
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
+
# Exposes a presenter method to the view for each provided name
|
18
|
+
def expose_presenter(*method_names)
|
17
19
|
presenters_module = Module.new do
|
18
20
|
method_names.each do |name|
|
19
21
|
module_eval <<-ruby_eval, __FILE__, __LINE__ + 1
|
20
22
|
def #{name}
|
21
|
-
controller.send('#{Presenter.
|
23
|
+
controller.send('#{Presenter.method_name_for(name)}')
|
22
24
|
end
|
23
25
|
ruby_eval
|
24
26
|
end
|
@@ -28,23 +30,20 @@ module PresenterRails
|
|
28
30
|
|
29
31
|
private
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
if
|
34
|
-
|
35
|
-
|
36
|
-
"which is either a non private method or overrides an existing method of the same name. " \
|
37
|
-
"Consider using a different presenter name\n" \
|
38
|
-
"#{caller.first}"
|
33
|
+
# Defines a private presenter method that invokes the provided block
|
34
|
+
def define_presenter_method!(methods, &block)
|
35
|
+
if methods.size != 1
|
36
|
+
Kernel.abort "[ERROR] You are providing a block for the `#{methods.join(', ')}` methods, " \
|
37
|
+
"but you can only provide a block for a single presenter at a time.\n #{caller.second}"
|
39
38
|
end
|
39
|
+
presenter_method = methods.first
|
40
|
+
define_method presenter_method, &block
|
41
|
+
private presenter_method
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.presenter_method_name(name)
|
45
|
+
# Name of the presenter methods
|
46
|
+
def self.method_name_for(name)
|
48
47
|
"#{name}_presenter"
|
49
48
|
end
|
50
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: presenter_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|