Skip to content

Commit 1dea49e

Browse files
committed
Rename OperationProcessor to Processor
1 parent 483da3e commit 1dea49e

7 files changed

Lines changed: 41 additions & 41 deletions

File tree

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,9 +1118,9 @@ Callbacks can be defined for the following `JSONAPI::Resource` events:
11181118
- `:remove_to_one_link`
11191119
- `:replace_fields`
11201120
1121-
##### `JSONAPI::OperationProcessor` Callbacks
1121+
##### `JSONAPI::Processor` Callbacks
11221122
1123-
Callbacks can also be defined for `JSONAPI::OperationProcessor` events:
1123+
Callbacks can also be defined for `JSONAPI::Processor` events:
11241124
- `:operation`: Any individual operation.
11251125
- `:find`: A `find` operation is being processed.
11261126
- `:show`: A `show` operation is being processed.
@@ -1141,8 +1141,8 @@ See [Operation Processors] (#operation-processors) for details on using Operatio
11411141
##### `JSONAPI::OperationsProcessor` Callbacks (a removed feature)
11421142
11431143
Note: The `JSONAPI::OperationsProcessor` has been removed and replaced with the `JSONAPI::OperationDispatcher`
1144-
and `OperationProcessor` classes per resource. The callbacks have been renamed and moved to the
1145-
`OperationProcessor`s, with the exception of the `operations` callback which is now on the controller.
1144+
and `Processor` classes per resource. The callbacks have been renamed and moved to the
1145+
`Processor`s, with the exception of the `operations` callback which is now on the controller.
11461146
11471147
### Controllers
11481148
@@ -1385,10 +1385,10 @@ end
13851385

13861386
Operation Processors are called to perform the operation(s) that make up a request. The controller (through the `OperationDispatcher`), creates an `OperatorProcessor` to handle each operation. The processor is created based on the resource name, including the namespace. If a processor does not exist for a resource (namespace matters) the default operation processor is used instead. The default processor can be changed by a configuration setting.
13871387

1388-
Defining a custom `OperationProcessor` allows for custom callback handling of each operation type for each resource type. For example:
1388+
Defining a custom `Processor` allows for custom callback handling of each operation type for each resource type. For example:
13891389

13901390
```ruby
1391-
class Api::V4::BookOperationProcessor < JSONAPI::OperationProcessor
1391+
class Api::V4::BookProcessor < JSONAPI::Processor
13921392
after_find do
13931393
unless @results.is_a?(JSONAPI::ErrorsOperationResult)
13941394
@result.meta[:total_records_found] = @result.record_count
@@ -1402,7 +1402,7 @@ feature only for example purposes), if there wasn't an error in the operation.
14021402
`find` method as well if a different behavior is needed, for example:
14031403

14041404
```ruby
1405-
class Api::V4::BookOperationProcessor < JSONAPI::OperationProcessor
1405+
class Api::V4::BookProcessor < JSONAPI::Processor
14061406
def find
14071407
filters = params[:filters]
14081408
include_directives = params[:include_directives]
@@ -1861,9 +1861,9 @@ JSONAPI.configure do |config|
18611861
#:underscored_route, :camelized_route, :dasherized_route, or custom
18621862
config.route_format = :dasherized_route
18631863
1864-
# Default OperationProcessor, used if a resource specific one is not defined.
1864+
# Default Processor, used if a resource specific one is not defined.
18651865
# Must be a class
1866-
config.default_operation_processor_klass = JSONAPI::OperationProcessor
1866+
config.default_processor_klass = JSONAPI::Processor
18671867
18681868
#:integer, :uuid, :string, or custom (provide a proc)
18691869
config.resource_key_type = :integer

lib/jsonapi-resources.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
require 'jsonapi/error_codes'
1616
require 'jsonapi/request'
1717
require 'jsonapi/operation_dispatcher'
18-
require 'jsonapi/operation_processor'
18+
require 'jsonapi/processor'
1919
require 'jsonapi/relationship'
2020
require 'jsonapi/include_directives'
2121
require 'jsonapi/operation_result'

lib/jsonapi/configuration.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'jsonapi/formatter'
2-
require 'jsonapi/operation_processor'
2+
require 'jsonapi/processor'
33
require 'concurrent'
44

55
module JSONAPI
@@ -14,7 +14,7 @@ class Configuration
1414
:default_paginator,
1515
:default_page_size,
1616
:maximum_page_size,
17-
:default_operation_processor_klass,
17+
:default_processor_klass,
1818
:use_text_errors,
1919
:top_level_links_include_pagination,
2020
:top_level_meta_include_record_count,
@@ -78,7 +78,7 @@ def initialize
7878

7979
# The default Operation Processor to use if one is not defined specifically
8080
# for a Resource.
81-
self.default_operation_processor_klass = JSONAPI::OperationProcessor
81+
self.default_processor_klass = JSONAPI::Processor
8282

8383
# Formatter Caching
8484
# Set to false to disable caching of string operations on keys and links.
@@ -148,8 +148,8 @@ def exception_class_whitelisted?(e)
148148
@exception_class_whitelist.flatten.any? { |k| e.class.ancestors.include?(k) }
149149
end
150150

151-
def default_operation_processor_klass=(default_operation_processor_klass)
152-
@default_operation_processor_klass = default_operation_processor_klass
151+
def default_processor_klass=(default_processor_klass)
152+
@default_processor_klass = default_processor_klass
153153
end
154154

155155
attr_writer :allow_include, :allow_sort, :allow_filter

lib/jsonapi/operation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def initialize(operation_type, resource_klass, options)
99
end
1010

1111
def transactional
12-
JSONAPI::OperationProcessor._operation_processor_from_resource_type(resource_klass).transactional(operation_type)
12+
JSONAPI::Processor._processor_from_resource_type(resource_klass).transactional(operation_type)
1313
end
1414

1515
def process
@@ -18,7 +18,7 @@ def process
1818

1919
private
2020
def processor
21-
JSONAPI::OperationProcessor.operation_processor_instance_for(resource_klass, operation_type, options)
21+
JSONAPI::Processor.processor_instance_for(resource_klass, operation_type, options)
2222
end
2323
end
2424
end
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module JSONAPI
2-
class OperationProcessor
2+
class Processor
33
include Callbacks
44
define_jsonapi_resources_callbacks :find,
55
:show,
@@ -18,17 +18,17 @@ class OperationProcessor
1818
:operation
1919

2020
class << self
21-
def operation_processor_instance_for(resource_klass, operation_type, params)
22-
_operation_processor_from_resource_type(resource_klass).new(resource_klass, operation_type, params)
21+
def processor_instance_for(resource_klass, operation_type, params)
22+
_processor_from_resource_type(resource_klass).new(resource_klass, operation_type, params)
2323
end
2424

25-
def _operation_processor_from_resource_type(resource_klass)
26-
operation_processor = resource_klass.name.gsub(/Resource$/,'OperationProcessor').safe_constantize
27-
if operation_processor.nil?
28-
operation_processor = JSONAPI.configuration.default_operation_processor_klass
25+
def _processor_from_resource_type(resource_klass)
26+
processor = resource_klass.name.gsub(/Resource$/,'Processor').safe_constantize
27+
if processor.nil?
28+
processor = JSONAPI.configuration.default_processor_klass
2929
end
3030

31-
operation_processor
31+
processor
3232
end
3333

3434
def transactional(operation_type)

test/controllers/controller_test.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_index
1717

1818
def test_exception_class_whitelist
1919
original_config = JSONAPI.configuration.dup
20-
$PostOperationProcessorRaisesErrors = true
20+
$PostProcessorRaisesErrors = true
2121
# test that the operations dispatcher rescues the error when it
2222
# has not been added to the exception_class_whitelist
2323
get :index
@@ -28,14 +28,14 @@ def test_exception_class_whitelist
2828
get :index
2929
assert_response 403
3030
ensure
31-
$PostOperationProcessorRaisesErrors = false
31+
$PostProcessorRaisesErrors = false
3232
JSONAPI.configuration = original_config
3333
end
3434

3535
def test_on_server_error_block_callback_with_exception
3636
original_config = JSONAPI.configuration.dup
3737
JSONAPI.configuration.exception_class_whitelist = []
38-
$PostOperationProcessorRaisesErrors = true
38+
$PostProcessorRaisesErrors = true
3939

4040
@controller.class.instance_variable_set(:@callback_message, "none")
4141
BaseController.on_server_error do
@@ -49,14 +49,14 @@ def test_on_server_error_block_callback_with_exception
4949
assert_equal "Internal Server Error", json_response['errors'][0]['title']
5050
assert_equal "Internal Server Error", json_response['errors'][0]['detail']
5151
ensure
52-
$PostOperationProcessorRaisesErrors = false
52+
$PostProcessorRaisesErrors = false
5353
JSONAPI.configuration = original_config
5454
end
5555

5656
def test_on_server_error_method_callback_with_exception
5757
original_config = JSONAPI.configuration.dup
5858
JSONAPI.configuration.exception_class_whitelist = []
59-
$PostOperationProcessorRaisesErrors = true
59+
$PostProcessorRaisesErrors = true
6060

6161
#ignores methods that don't exist
6262
@controller.class.on_server_error :set_callback_message, :a_bogus_method
@@ -68,7 +68,7 @@ def test_on_server_error_method_callback_with_exception
6868
# test that it renders the default server error response
6969
assert_equal "Internal Server Error", json_response['errors'][0]['title']
7070
ensure
71-
$PostOperationProcessorRaisesErrors = false
71+
$PostProcessorRaisesErrors = false
7272
JSONAPI.configuration = original_config
7373
end
7474

@@ -84,7 +84,7 @@ def test_on_server_error_callback_without_exception
8484
# test that it does not render error
8585
assert json_response.key?('data')
8686
ensure
87-
$PostOperationProcessorRaisesErrors = false
87+
$PostProcessorRaisesErrors = false
8888
end
8989

9090
def test_index_filter_with_empty_result
@@ -3387,13 +3387,13 @@ def test_not_whitelisted_error_in_controller
33873387

33883388
def test_whitelisted_error_in_controller
33893389
original_config = JSONAPI.configuration.dup
3390-
$PostOperationProcessorRaisesErrors = true
3390+
$PostProcessorRaisesErrors = true
33913391
JSONAPI.configuration.exception_class_whitelist = [PostsController::SubSpecialError]
33923392
assert_raises PostsController::SubSpecialError do
33933393
get :show, params: {id: '1'}
33943394
end
33953395
ensure
33963396
JSONAPI.configuration = original_config
3397-
$PostOperationProcessorRaisesErrors = false
3397+
$PostProcessorRaisesErrors = false
33983398
end
33993399
end

test/fixtures/active_record.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,8 +1573,8 @@ class FlatPostResource < JSONAPI::Resource
15731573
class FlatPostsController < JSONAPI::ResourceController
15741574
end
15751575

1576-
# CustomOperationProcessors
1577-
class Api::V4::BookOperationProcessor < JSONAPI::OperationProcessor
1576+
# CustomProcessors
1577+
class Api::V4::BookProcessor < JSONAPI::Processor
15781578
after_find do
15791579
unless @results.is_a?(JSONAPI::ErrorsOperationResult)
15801580
@result.meta[:total_records] = @result.record_count
@@ -1583,9 +1583,9 @@ class Api::V4::BookOperationProcessor < JSONAPI::OperationProcessor
15831583
end
15841584
end
15851585

1586-
class PostOperationProcessor < JSONAPI::OperationProcessor
1586+
class PostProcessor < JSONAPI::Processor
15871587
def find
1588-
if $PostOperationProcessorRaisesErrors
1588+
if $PostProcessorRaisesErrors
15891589
raise PostsController::SubSpecialError
15901590
end
15911591
# puts("In custom Operations Processor without Namespace")
@@ -1602,9 +1602,9 @@ def find
16021602

16031603
module Api
16041604
module V7
1605-
class CategoryOperationProcessor < JSONAPI::OperationProcessor
1605+
class CategoryProcessor < JSONAPI::Processor
16061606
def show
1607-
if $PostOperationProcessorRaisesErrors
1607+
if $PostProcessorRaisesErrors
16081608
raise PostsController::SubSpecialError
16091609
end
16101610
# puts("In custom Operations Processor without Namespace")
@@ -1616,7 +1616,7 @@ def show
16161616

16171617
module Api
16181618
module V1
1619-
class PostOperationProcessor < JSONAPI::OperationProcessor
1619+
class PostProcessor < JSONAPI::Processor
16201620
def show
16211621
# puts("In custom Operations Processor with Namespace")
16221622
super

0 commit comments

Comments
 (0)