presenter-pattern 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.0') do |p|
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"
@@ -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.layout nil
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 :xml, :json
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
- {"data" => @__rval}
81
+ {@view_var_name => @__rval}
67
82
  end
68
83
  end
69
84
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{presenter-pattern}
5
- s.version = "0.3.0"
5
+ s.version = "0.3.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Josh Leven"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: presenter-pattern
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: