presenter-pattern 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/presenter-pattern.rb +19 -4
- data/presenter-pattern.gemspec +1 -1
- metadata +1 -1
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('presenter-pattern', '0.3.
|
5
|
+
Echoe.new('presenter-pattern', '0.3.1') do |p|
|
6
6
|
p.description = "Enables and enforces the presenter pattern in rails"
|
7
7
|
p.url = "https://github.com/jleven/presenter-pattern"
|
8
8
|
p.author = "Josh Leven"
|
data/lib/presenter-pattern.rb
CHANGED
@@ -28,16 +28,26 @@ module PresenterPattern
|
|
28
28
|
custom_api = self.dup
|
29
29
|
custom_api.class_eval do
|
30
30
|
define_singleton_method :included do |host_class|
|
31
|
-
host_class
|
32
|
-
host_class.respond_to *formats
|
31
|
+
do_included(host_class, *formats)
|
33
32
|
end
|
34
33
|
end
|
35
34
|
custom_api
|
36
35
|
end
|
37
36
|
|
38
37
|
def self.included(host_class)
|
38
|
+
do_included(host_class, :xml, :json)
|
39
|
+
end
|
40
|
+
|
41
|
+
module ClassMethods
|
42
|
+
def view_var_name(name)
|
43
|
+
@view_var_name = name.to_s
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.do_included(host_class, *formats)
|
39
48
|
host_class.layout nil
|
40
|
-
host_class.respond_to
|
49
|
+
host_class.respond_to *formats
|
50
|
+
host_class.extend PresenterPattern::API::ClassMethods
|
41
51
|
end
|
42
52
|
|
43
53
|
# enforces simple api response
|
@@ -52,6 +62,11 @@ module PresenterPattern
|
|
52
62
|
#fail if action calls 'render'
|
53
63
|
raise NoExplicitRender, "Controllers implementing the PresenterPattern::API must not call any render methods" if response_body
|
54
64
|
|
65
|
+
#set the view variable
|
66
|
+
name = self.class.instance_variable_get(:@view_var_name)
|
67
|
+
name = name.pluralize if name && method_name.to_s == "index" #pluralize the @view_var_name if it was set at the class and this is GET/index
|
68
|
+
@view_var_name = name || "data"
|
69
|
+
|
55
70
|
#always follow responder pattern passing in the action's return value
|
56
71
|
respond_with @__rval, (@respond_with_opts || {})
|
57
72
|
end
|
@@ -63,7 +78,7 @@ module PresenterPattern
|
|
63
78
|
|
64
79
|
#only the @__rval variable (set in send_action) is passed through to the view
|
65
80
|
def view_assigns
|
66
|
-
{
|
81
|
+
{@view_var_name => @__rval}
|
67
82
|
end
|
68
83
|
end
|
69
84
|
end
|
data/presenter-pattern.gemspec
CHANGED