marr 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 543dbce426c58c432cfeee42629f3e4e9f22a35c279d86d76fc807db04ccc51c
4
- data.tar.gz: eb3d0cd1c22ac0b80e868eacba83f3a4b8df91d176105884375979031ca3fc74
3
+ metadata.gz: e909f2295291352697f897d314db04003ff1103f07ee81f55dba2c50e1b0e130
4
+ data.tar.gz: 2bcdcfe975f88a9c243228fedf077d905977eb6075bc79aab046a1e2fec1b3c4
5
5
  SHA512:
6
- metadata.gz: 5f9465b57a19934e732bf0eafd930f0bc25ffdcccf652d8cd00595036e756dcc38ef40b6f1546d55ce1ad009f8182810ca6a45dfdc536657166f47fe2978a6e2
7
- data.tar.gz: 17aa45daf2672e3bcabf8b71d5538fc6fa21455e06cd9fbf069bd111da94116af1023e519ea48bc40a2352fb2804febfa0afd1679e454961cce74562b99138fa
6
+ metadata.gz: b47f0f88c16407dd5f5fa7aa3d47c8fff12ded138bd65aaee6f96592e9a7b5206205191decb6d3f269828ad7570b88bb5447417036671c2696f52499c7ef8884
7
+ data.tar.gz: b2c4454732225e845cbbd2d092fbd57e212546edb7f2c7539fff1c37e2b4517b4ee254cca9d3b8cbadb2c2b4eb9bb7e6974e3157305431f8372ea10001d5d5a0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- marr (0.1.1)
4
+ marr (0.1.2)
5
5
  activesupport (>= 6.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -27,8 +27,9 @@ Or install it yourself as:
27
27
  ```json
28
28
  {
29
29
  "errors": {
30
- "code": "GroupError",
31
- "title": "GroupInvalid",
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
- raise_meme_error
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
- raise_meme_error(controller: self, subcode: :meme_invalid, object: @meme)
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::Api::Error.configure do |config|
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 MemeError < ::Marr::ApiError
82
+ class UnprocessableGroup < ::Marr::ApiError
82
83
  def message
83
- "There was an issue processing the meme"
84
+ "Request can not be processed."
84
85
  end
85
86
 
86
87
  def subcodes
87
88
  super({
88
- meme_invalid: 'This meme is invalid.',
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
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "bundler/setup"
5
+ require "./lib/marr"
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -1,10 +1,9 @@
1
1
  require 'active_support'
2
- require 'marr/api/error'
3
2
 
4
3
  module Marr
5
4
  module Api
6
5
  module ErrorEngine
7
- ::Marr::Api::Error.all_errors.each do |error|
6
+ ::Marr.all_errors.each do |error|
8
7
  name = error[:name]
9
8
  namespace = error[:namespace]
10
9
 
@@ -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(status: 422)
46
- @override_status&.integer? ? @override_status : status
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::Api::Error.configuration.custom_render
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::Api::Error.configuration.custom_render
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: subcode,
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::Api::Error.configuration.trace_id_length / 2
115
+ Marr.configuration.trace_id_length / 2
113
116
  end
114
117
 
115
118
  def set_resource
@@ -1,9 +1,11 @@
1
- class Configuration
2
- attr_accessor :namespaces, :trace_id_length, :custom_render
1
+ module Marr
2
+ class Configuration
3
+ attr_accessor :namespaces, :trace_id_length, :custom_render
3
4
 
4
- def initialize
5
- @namespaces = []
6
- @trace_id_length = 8
7
- @custom_render = false
5
+ def initialize
6
+ @namespaces = []
7
+ @trace_id_length = 8
8
+ @custom_render = false
9
+ end
8
10
  end
9
11
  end
@@ -0,0 +1,3 @@
1
+ module Marr
2
+ VERSION = "0.1.2"
3
+ end
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,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/marr/api/error/version"
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::Api::Error::VERSION
7
+ spec.version = Marr::VERSION
8
8
  spec.authors = ["Memereply", "Micah Bowie"]
9
9
  spec.email = ["engineering@memereply.io"]
10
10
 
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.1
4
+ version: 0.1.2
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-01 00:00:00.000000000 Z
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/api/error.rb
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: []
@@ -1,7 +0,0 @@
1
- module Marr
2
- module Api
3
- module Error
4
- VERSION = "0.1.1"
5
- end
6
- end
7
- end
@@ -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