marr 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +9 -9
- data/bin/console +1 -0
- data/lib/marr/api/error_engine.rb +1 -2
- data/lib/marr/api_error.rb +14 -11
- data/lib/marr/configuration.rb +8 -6
- data/lib/marr/version.rb +3 -0
- data/lib/marr.rb +38 -0
- data/marr.gemspec +5 -2
- metadata +4 -4
- data/lib/marr/api/error/version.rb +0 -7
- data/lib/marr/api/error.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66ce919bb7a333d43960ef38b2c43af4851169441d4db40388567a51e2af110d
|
4
|
+
data.tar.gz: cf49f56be589f2ebab4b3ac76940c58c9e86d37d7dcec7bf4008ab2899c1f052
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9e35c72530bc24a1ea4d6d354bf9f6832c89a5e50c1127651d9fdedcfe4f62c496280a4dd470ee084fe2ec8189c945fbe86a23ffa715285c2ab2c3ad00c24b7
|
7
|
+
data.tar.gz: 9da3772f4c8048edae8786ffc606774568c24e861a35307b612e3b86a5c611a26edc0e74a6b614e9e823107acb36572fe5938a9ad0bebd5449b20769a8dad9c8
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -27,8 +27,9 @@ Or install it yourself as:
|
|
27
27
|
```json
|
28
28
|
{
|
29
29
|
"errors": {
|
30
|
-
"
|
31
|
-
"
|
30
|
+
"id": "6CA01AF9E592595F",
|
31
|
+
"code": "UnprocessableGroup",
|
32
|
+
"title": "Request can not be processed.",
|
32
33
|
"detail": "The Group can not be saved. Invalid or missing data.",
|
33
34
|
"meta": {
|
34
35
|
"object_errors": [
|
@@ -52,13 +53,13 @@ Or install it yourself as:
|
|
52
53
|
There is a method automatically created for each each class that inherits from Marr::ApiError. The method is preprended with 'raise'.
|
53
54
|
|
54
55
|
```ruby
|
55
|
-
|
56
|
+
raise_unprocessable_group_error
|
56
57
|
```
|
57
58
|
|
58
59
|
You can also pass in options to your method for a more robust response:
|
59
60
|
|
60
61
|
```ruby
|
61
|
-
|
62
|
+
raise_unprocessable_group_error(controller: self, subcode: :missing_data, object: @group)
|
62
63
|
```
|
63
64
|
|
64
65
|
## Setup
|
@@ -66,7 +67,7 @@ You can also pass in options to your method for a more robust response:
|
|
66
67
|
Configure the gem. For the gem to recognize the descendant classes you have to provide the name space the errors are under.
|
67
68
|
|
68
69
|
```ruby
|
69
|
-
Marr
|
70
|
+
Marr.configure do |config|
|
70
71
|
config.namespaces = ['Api::V1::Errors']
|
71
72
|
config.trace_id_length = 16
|
72
73
|
end
|
@@ -78,15 +79,14 @@ Create a new Error that inherits from the ApiError class. The class needs to be
|
|
78
79
|
module Api
|
79
80
|
module V1
|
80
81
|
module Errors
|
81
|
-
class
|
82
|
+
class UnprocessableGroup < ::Marr::ApiError
|
82
83
|
def message
|
83
|
-
"
|
84
|
+
"Request can not be processed."
|
84
85
|
end
|
85
86
|
|
86
87
|
def subcodes
|
87
88
|
super({
|
88
|
-
|
89
|
-
meme_too_large: 'This meme is too damn big nephew',
|
89
|
+
missing_data: 'The Group can not be saved. Invalid or missing data.',
|
90
90
|
})
|
91
91
|
end
|
92
92
|
end
|
data/bin/console
CHANGED
data/lib/marr/api_error.rb
CHANGED
@@ -9,7 +9,7 @@ module Marr
|
|
9
9
|
def initialize(attributes={})
|
10
10
|
@controller = attributes[:controller]
|
11
11
|
@object = attributes[:object]
|
12
|
-
@resource = attributes[:resource] || 'Resource'
|
12
|
+
@resource = attributes[:resource] || 'Resource'.freeze
|
13
13
|
@subcode = attributes[:subcode]
|
14
14
|
@override_detail = attributes[:override_detail]
|
15
15
|
@override_status = attributes[:override_status]
|
@@ -20,10 +20,6 @@ module Marr
|
|
20
20
|
set_resource
|
21
21
|
end
|
22
22
|
|
23
|
-
# Error name => code
|
24
|
-
# Status => status
|
25
|
-
# Subcodes => title
|
26
|
-
# message => detail
|
27
23
|
def object_errors
|
28
24
|
return [] unless @object.present?
|
29
25
|
return [] unless @object&.errors&.full_messages.present?
|
@@ -42,8 +38,9 @@ module Marr
|
|
42
38
|
@object_errors
|
43
39
|
end
|
44
40
|
|
45
|
-
def status
|
46
|
-
|
41
|
+
def status
|
42
|
+
default_status = '422'
|
43
|
+
@override_status&.integer? ? @override_status.to_s : default_status
|
47
44
|
end
|
48
45
|
|
49
46
|
def message
|
@@ -62,6 +59,10 @@ module Marr
|
|
62
59
|
@subcode.to_s.camelcase
|
63
60
|
end
|
64
61
|
|
62
|
+
def subcode_detail
|
63
|
+
subcodes[@subcode].present? ? subcodes[@subcode] : ''
|
64
|
+
end
|
65
|
+
|
65
66
|
def detail
|
66
67
|
return '' unless @override_detail.present? || subcodes[@subcode].present?
|
67
68
|
|
@@ -77,7 +78,7 @@ module Marr
|
|
77
78
|
end
|
78
79
|
|
79
80
|
def render
|
80
|
-
if Marr
|
81
|
+
if Marr.configuration.custom_render
|
81
82
|
custom_render
|
82
83
|
else
|
83
84
|
default_render.to_json
|
@@ -85,7 +86,7 @@ module Marr
|
|
85
86
|
end
|
86
87
|
|
87
88
|
def custom_render
|
88
|
-
if Marr
|
89
|
+
if Marr.configuration.custom_render
|
89
90
|
raise NotImplementedError, 'Message must be implemented. Add Error message method.'
|
90
91
|
else
|
91
92
|
nil
|
@@ -95,9 +96,11 @@ module Marr
|
|
95
96
|
def default_render
|
96
97
|
{
|
97
98
|
errors: {
|
99
|
+
id: trace_id,
|
100
|
+
status: status,
|
98
101
|
code: type,
|
99
102
|
title: message,
|
100
|
-
detail:
|
103
|
+
detail: subcode_detail,
|
101
104
|
meta: {
|
102
105
|
object_errors: object_errors,
|
103
106
|
trace_id: trace_id,
|
@@ -109,7 +112,7 @@ module Marr
|
|
109
112
|
private
|
110
113
|
|
111
114
|
def trace_id_length
|
112
|
-
Marr
|
115
|
+
Marr.configuration.trace_id_length / 2
|
113
116
|
end
|
114
117
|
|
115
118
|
def set_resource
|
data/lib/marr/configuration.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Marr
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :namespaces, :trace_id_length, :custom_render
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def initialize
|
6
|
+
@namespaces = []
|
7
|
+
@trace_id_length = 8
|
8
|
+
@custom_render = false
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
data/lib/marr/version.rb
ADDED
data/lib/marr.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'active_support'
|
3
|
+
require 'json'
|
4
|
+
require 'securerandom'
|
5
|
+
require 'marr/configuration'
|
6
|
+
require 'marr/version'
|
7
|
+
|
8
|
+
module Marr
|
9
|
+
autoload :Configuration, 'marr/configuration'
|
10
|
+
autoload :ApiError, 'marr/api_error'
|
11
|
+
|
12
|
+
module Api
|
13
|
+
autoload :ErrorEngine, 'marr/api/error_engine'
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def configuration
|
18
|
+
@configuration ||= ::Marr::Configuration.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure
|
22
|
+
yield(configuration)
|
23
|
+
load('./lib/marr/api/error_engine.rb')
|
24
|
+
end
|
25
|
+
|
26
|
+
def all_errors
|
27
|
+
return [] if self.configuration.namespaces.blank?
|
28
|
+
|
29
|
+
self.configuration.namespaces.map(&:constantize).map do |namespace|
|
30
|
+
namespace.constants.map { |x| { namespace: namespace, name: x.to_s.underscore } }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def version
|
35
|
+
::Marr::VERSION
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/marr.gemspec
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "lib/marr/
|
3
|
+
require_relative "lib/marr/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "marr" # Memereply Api Rescue Response aka marr
|
7
|
-
spec.version = Marr::
|
7
|
+
spec.version = Marr::VERSION
|
8
8
|
spec.authors = ["Memereply", "Micah Bowie"]
|
9
9
|
spec.email = ["engineering@memereply.io"]
|
10
10
|
|
11
11
|
spec.summary = "Dynamically rescue errors and render a structured JSON response to client applications"
|
12
12
|
spec.description = "Dynamically rescue errors and render a structured JSON response to client applications"
|
13
13
|
spec.homepage = "https://github.com/meme-reply/marr"
|
14
|
+
|
15
|
+
spec.files = Dir["{lib}/**/*", "LICENSE.txt", "README.md"]
|
16
|
+
spec.require_paths = ["lib"]
|
14
17
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
15
18
|
|
16
19
|
spec.metadata["homepage_uri"] = spec.homepage
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Memereply
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-05-
|
12
|
+
date: 2023-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -86,11 +86,11 @@ files:
|
|
86
86
|
- Rakefile
|
87
87
|
- bin/console
|
88
88
|
- bin/setup
|
89
|
-
- lib/marr
|
90
|
-
- lib/marr/api/error/version.rb
|
89
|
+
- lib/marr.rb
|
91
90
|
- lib/marr/api/error_engine.rb
|
92
91
|
- lib/marr/api_error.rb
|
93
92
|
- lib/marr/configuration.rb
|
93
|
+
- lib/marr/version.rb
|
94
94
|
- marr.gemspec
|
95
95
|
homepage: https://github.com/meme-reply/marr
|
96
96
|
licenses: []
|
data/lib/marr/api/error.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'marr/api/error/version'
|
2
|
-
require 'marr/configuration'
|
3
|
-
require 'marr/api_error'
|
4
|
-
|
5
|
-
module Marr
|
6
|
-
module Api
|
7
|
-
module Error
|
8
|
-
class << self
|
9
|
-
def configuration
|
10
|
-
@configuration ||= Configuration.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def configure
|
14
|
-
yield(configuration)
|
15
|
-
load 'marr/api/error_engine'
|
16
|
-
end
|
17
|
-
|
18
|
-
def all_errors
|
19
|
-
return [] if self.configuration.namespaces.blank?
|
20
|
-
|
21
|
-
self.configuration.namespaces.map(&:constantize).map do |namespace|
|
22
|
-
namespace.constants.map { |x| { namespace: namespace, name: x.to_s.underscore } }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|