api_logic 0.0.1 → 0.0.2

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.
@@ -7,6 +7,8 @@ module ApiLogic
7
7
 
8
8
 
9
9
  included do
10
+ self.responder = ::ApiLogic::Responder
11
+
10
12
  guess_model
11
13
 
12
14
  def self.inherited(subclass)
@@ -19,7 +21,6 @@ module ApiLogic
19
21
 
20
22
  module ClassMethods
21
23
 
22
- resonder = ::ApiLogic::Responder
23
24
 
24
25
  attr_reader :model_class
25
26
  alias :model :model_class
@@ -6,22 +6,30 @@ module ApiLogic
6
6
 
7
7
  def respond
8
8
 
9
- # An API controller might want to tailor its response
10
- # with a RABL template. If a template exists, render that.
11
- #
12
- # Also, if the resource is nil or if it doesn't respond to
13
- # :to_#{format}, fall back to the default render functionality.
14
- #
15
- template_path = File.join(controller.controller_path, controller.action_name)
16
- if resource.nil? || !resourceful? || controller.template_exists?(template_path)
17
- render
9
+ # api_behavior checks for errors in Rails 3.0.3, but not in Rails
10
+ # 3.1.0. To be sure that we behave correctly, check here.
11
+ if has_errors? && !get?
12
+ controller.render format => resource.errors, :status => :unprocessable_entity
13
+
18
14
  else
19
15
 
20
- # api_behavior takes as a parameter the error it will throw if
21
- # the resource does not respond to :to_#{format}. (Since we've
22
- # already checked :resourceful?, this error should never be thrown,
23
- # but just in case, we'll supply NotImplementedError.)
24
- api_behavior(NotImplementedError)
16
+ # An API controller might want to tailor its response
17
+ # with a RABL template. If a template exists, render that.
18
+ #
19
+ # Also, if the resource is nil or if it doesn't respond to
20
+ # :to_#{format}, fall back to the default render functionality.
21
+ #
22
+ template_path = File.join(controller.controller_path, controller.action_name)
23
+ if resource.nil? || !resourceful? || controller.template_exists?(template_path)
24
+ render
25
+ else
26
+
27
+ # api_behavior takes as a parameter the error it will throw if
28
+ # the resource does not respond to :to_#{format}. (Since we've
29
+ # already checked :resourceful?, this error should never be thrown,
30
+ # but just in case, we'll supply NotImplementedError.)
31
+ api_behavior(NotImplementedError)
32
+ end
25
33
  end
26
34
  end
27
35
 
@@ -31,3 +39,4 @@ end
31
39
 
32
40
  # Refer to the source of ActionController::Responder:
33
41
  # https://github.com/rails/rails/blob/v3.0.3/actionpack/lib/action_controller/metal/responder.rb#L155
42
+ # https://github.com/rails/rails/blob/v3.1.0/actionpack/lib/action_controller/metal/responder.rb#L198
@@ -1,3 +1,3 @@
1
1
  module ApiController
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,8 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_logic
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
6
10
  platform: ruby
7
11
  authors:
8
12
  - Robert Lail
@@ -10,17 +14,18 @@ autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
16
 
13
- date: 2011-08-18 00:00:00 -05:00
17
+ date: 2011-09-08 00:00:00 -05:00
14
18
  default_executable:
15
19
  dependencies:
16
20
  - !ruby/object:Gem::Dependency
17
21
  name: activesupport
18
22
  prerelease: false
19
23
  requirement: &id001 !ruby/object:Gem::Requirement
20
- none: false
21
24
  requirements:
22
25
  - - ">="
23
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
24
29
  version: "0"
25
30
  type: :runtime
26
31
  version_requirements: *id001
@@ -28,10 +33,11 @@ dependencies:
28
33
  name: actionpack
29
34
  prerelease: false
30
35
  requirement: &id002 !ruby/object:Gem::Requirement
31
- none: false
32
36
  requirements:
33
37
  - - ">="
34
38
  - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
35
41
  version: "0"
36
42
  type: :runtime
37
43
  version_requirements: *id002
@@ -61,21 +67,23 @@ rdoc_options: []
61
67
  require_paths:
62
68
  - lib
63
69
  required_ruby_version: !ruby/object:Gem::Requirement
64
- none: false
65
70
  requirements:
66
71
  - - ">="
67
72
  - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
68
75
  version: "0"
69
76
  required_rubygems_version: !ruby/object:Gem::Requirement
70
- none: false
71
77
  requirements:
72
78
  - - ">="
73
79
  - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
74
82
  version: "0"
75
83
  requirements: []
76
84
 
77
85
  rubyforge_project: api_logic
78
- rubygems_version: 1.6.2
86
+ rubygems_version: 1.3.6
79
87
  signing_key:
80
88
  specification_version: 3
81
89
  summary: A lightweight mixin for making API controllers