Skip to content

Commit 45b94bd

Browse files
author
Sebastian Wilgosz
committed
Add top-level class documentation for all defined classes
1 parent cc7882b commit 45b94bd

File tree

7 files changed

+23
-2
lines changed

7 files changed

+23
-2
lines changed

lib/jsonapi_errors_handler.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
require 'jsonapi_errors_handler/error_mapper'
77
require 'jsonapi_errors_handler/error_serializer'
88

9+
# Allows to handle ruby errors and return the serialized JSON:API output
10+
#
911
module JsonapiErrorsHandler
1012
PREDEFINED_HASH = {
1113
'JsonapiErrorsHandler::Errors::Invalid' =>

lib/jsonapi_errors_handler/configuration.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33
require 'singleton'
44

55
module JsonapiErrorsHandler
6+
# Configuration class allowing to set up the initial behavior for the gem
7+
#
68
class Configuration
79
include Singleton
810

911
attr_writer :handle_unexpected
1012

13+
# Allows to override the configuration options
14+
# @param [Block] - list of options to be overwriten
15+
#
1116
def configure
1217
yield(self) if block_given?
1318
end
1419

20+
# Checks if unexpected errors should be handled by the gem
21+
# @return [Boolean]
22+
#
1523
def handle_unexpected?
1624
@handle_unexpected
1725
end

lib/jsonapi_errors_handler/error_mapper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# frozen_string_literal: true
22

33
module JsonapiErrorsHandler
4+
# Maps any of the given error classes into the serializable errors
5+
# from the predefined collection
6+
#
47
class ErrorMapper
58
@mapped_errors = {}
69

lib/jsonapi_errors_handler/error_serializer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require 'json'
44

55
module JsonapiErrorsHandler
6+
# Serializes the given error to match the JSON:API specification
7+
#
68
class ErrorSerializer
79
def initialize(error)
810
@error = error

lib/jsonapi_errors_handler/errors.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
module JsonapiErrorsHandler
4+
# A set of predefined, serializable HTTP error objects
5+
#
46
module Errors
57
end
68
end

lib/jsonapi_errors_handler/keys_stringifier.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
module JsonapiErrorsHandler
4+
# Allows to stringify keys on the given hash
5+
#
46
class KeysStringifier
57
def self.call(hash)
68
hash.reduce({}) do |h, (k, v)|

spec/error_mapper_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444

4545
it 'returns the original error if the instance had been risen' do
4646
JsonapiErrorsHandler::ErrorMapper.map_errors!(
47-
'JsonapiErrorsHandler::Errors::Forbidden' => 'JsonapiErrorsHandler::Errors::Forbidden'
47+
'JsonapiErrorsHandler::Errors::Forbidden' =>
48+
'JsonapiErrorsHandler::Errors::Forbidden'
4849
)
4950
expect(subject).to eq mapped_error
5051
expect(subject.detail).to eq('test')
@@ -56,7 +57,8 @@
5657

5758
it 'returns an instance of the risen error klass' do
5859
JsonapiErrorsHandler::ErrorMapper.map_errors!(
59-
'JsonapiErrorsHandler::Errors::Forbidden' => 'JsonapiErrorsHandler::Errors::Forbidden'
60+
'JsonapiErrorsHandler::Errors::Forbidden' =>
61+
'JsonapiErrorsHandler::Errors::Forbidden'
6062
)
6163
expect(subject).to eq mapped_error.new
6264
end

0 commit comments

Comments
 (0)