Skip to content

Commit 6104afb

Browse files
committed
Merge pull request #723 from cerebris/resource_controller_metal
ResourceControllerMetal
2 parents 6fa2997 + 17bd397 commit 6104afb

5 files changed

Lines changed: 37 additions & 18 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,22 @@ A jsonapi-controller generator is avaliable
11711171
rails generate jsonapi:controller contact
11721172
```
11731173
1174+
###### ResourceControllerMetal
1175+
1176+
`JSONAPI::Resources` also provides an alternative class to `ResourceController` called `ResourceControllerMetal`.
1177+
In order to provide a lighter weight controller option this strips the controller down to just the classes needed
1178+
to work with `JSONAPI::Resources`.
1179+
1180+
For example:
1181+
1182+
```ruby
1183+
class PeopleController < JSONAPI::ResourceControllerMetal
1184+
1185+
end
1186+
```
1187+
1188+
Note: This may not provide all of the expected controller capabilities if you are using additional gems such as DoorKeeper.
1189+
11741190
###### Serialization Options
11751191
11761192
Additional options can be passed to the serializer using the `serialization_options` method.

lib/jsonapi-resources.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'jsonapi/response_document'
44
require 'jsonapi/acts_as_resource_controller'
55
require 'jsonapi/resource_controller'
6+
require 'jsonapi/resource_controller_metal'
67
require 'jsonapi/resources/version'
78
require 'jsonapi/configuration'
89
require 'jsonapi/paginator'

lib/jsonapi/resource_controller.rb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
module JSONAPI
2-
class ResourceController < ActionController::Metal
3-
MODULES = [
4-
AbstractController::Rendering,
5-
ActionController::Rendering,
6-
ActionController::Renderers::All,
7-
ActionController::StrongParameters,
8-
ActionController::ForceSSL,
9-
ActionController::Instrumentation,
10-
JSONAPI::ActsAsResourceController
11-
].freeze
12-
13-
MODULES.each do |mod|
14-
include mod
15-
end
2+
class ResourceController < ActionController::Base
3+
include JSONAPI::ActsAsResourceController
164
end
175
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module JSONAPI
2+
class ResourceControllerMetal < ActionController::Metal
3+
MODULES = [
4+
AbstractController::Rendering,
5+
ActionController::Rendering,
6+
ActionController::Renderers::All,
7+
ActionController::StrongParameters,
8+
ActionController::ForceSSL,
9+
ActionController::Instrumentation,
10+
JSONAPI::ActsAsResourceController
11+
].freeze
12+
13+
MODULES.each do |mod|
14+
include mod
15+
end
16+
end
17+
end

test/fixtures/active_record.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ class Customer < Customer
546546
end
547547

548548
### CONTROLLERS
549-
class AuthorsController < JSONAPI::ResourceController
549+
class AuthorsController < JSONAPI::ResourceControllerMetal
550550
end
551551

552552
class PeopleController < JSONAPI::ResourceController
@@ -633,9 +633,6 @@ class BoatsController < JSONAPI::ResourceController
633633
class BooksController < JSONAPI::ResourceController
634634
end
635635

636-
class AuthorsController < JSONAPI::ResourceController
637-
end
638-
639636
### CONTROLLERS
640637
module Api
641638
module V1

0 commit comments

Comments
 (0)