json_errors 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c7bb942cf5ede276351ed16f0730c356a901a0892ba4b8d64afb0db71d6f797
4
- data.tar.gz: 586832722858d41b3ee436cdac4407428c2a3cf2fb9c3f9fffd1934177ecd189
3
+ metadata.gz: 82cdcb26c361de8eb6868ce702eeb97fd62ddc669d98518b8ed3334258ba1422
4
+ data.tar.gz: 93245dc766c1bc2765af83b43c2d25bb897e71b71d9238b58de0a72543e46119
5
5
  SHA512:
6
- metadata.gz: caa154ab9fed780b387f8d726663455598e2e13ebf9c8fab5126aec955098e62a199c640771892f53bb7c448a86e6c26707a19eb19a0c49ba595415b4ab88414
7
- data.tar.gz: 64d0d4bc21882a908aa4b871e3f872ca0164ff577c5ae44c36d6186309751897d8f4a202c72e9bedb051fe527872261bcd77204cfe0225cefe66edbb51422709
6
+ metadata.gz: dcbe2db6646811d99de69ec3ca988c68d46c1e0631561c9fa34b28df579006a8669927e048ceb5178bb34d74466efe425094dd6550ab9c2b6209b1d8838db00d
7
+ data.tar.gz: 1d420a644a9d66435105197c4bd69d8c516cf8576a2bc8839322efe18e8d8bac47524144a9da7ed366e9be4943a05155f6be5628d6fbbe89ddc62d42d00c92ad
@@ -10,10 +10,10 @@ jobs:
10
10
  - name: Set up Ruby
11
11
  uses: ruby/setup-ruby@v1
12
12
  with:
13
- ruby-version: 3.0.1
13
+ ruby-version: 3.4.1
14
14
  - name: Run the default task
15
15
  run: |
16
- gem install bundler -v 2.2.15
16
+ gem install bundler -v 2.6.5
17
17
  bundle install
18
18
  bundle exec rake rubocop
19
19
  bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,6 +1,11 @@
1
+ plugins:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
1
5
  AllCops:
2
6
  TargetRubyVersion: 3.0
3
7
  NewCops: enable
8
+ SuggestExtensions: false
4
9
 
5
10
  Layout/LineLength:
6
11
  Max: 120
@@ -10,3 +15,27 @@ Metrics/BlockLength:
10
15
  Exclude:
11
16
  - spec/**/*
12
17
  - config/**/*
18
+
19
+ RSpec/SpecFilePathFormat:
20
+ Enabled: false
21
+
22
+ RSpec/VerifiedDoubles:
23
+ Enabled: false
24
+
25
+ RSpec/NestedGroups:
26
+ Enabled: false
27
+
28
+ RSpec/MultipleExpectations:
29
+ Enabled: false
30
+
31
+ RSpec/SubjectStub:
32
+ Enabled: false
33
+
34
+ RSpec/MessageSpies:
35
+ Enabled: false
36
+
37
+ RSpec/DescribedClass:
38
+ Enabled: false
39
+
40
+ RSpec/VerifiedDoubleReference:
41
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.2] - 2025-03-04
4
+
5
+ - bugfix: Validation errors
6
+
7
+ ## [0.3.2] - 2025-03-04
8
+
9
+ - bugfix: Active record validation errors were never shown
10
+
3
11
  ## [0.3.1] - 2025-02-27
4
12
 
5
13
  - bugfix: Wrong ActiveRecord error format
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_errors (0.3.0)
4
+ json_errors (0.3.2)
5
5
  activesupport (~> 8.0)
6
6
 
7
7
  GEM
data/json_errors.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ['lib']
29
29
 
30
- spec.add_dependency 'activesupport', "~> 8.0"
30
+ spec.add_dependency 'activesupport', '~> 8.0'
31
31
 
32
32
  # For more information and examples about making a new gem, checkout our
33
33
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -10,7 +10,7 @@ module JsonErrors
10
10
  attr_accessor :error_dictionary, :custom_codes
11
11
 
12
12
  def self.missing_config_error_meesage
13
- <<~'MSG'
13
+ <<~MSG
14
14
  Configuration is missing. Run the generattor: `bundle exec rails g json_errors::install`
15
15
  or create the initializer yourself.
16
16
  Check out the README https://github.com/nomtek/JsonErrors/blob/main/README.md
@@ -3,11 +3,11 @@
3
3
  module JsonErrors
4
4
  # Error class for custom payload errors
5
5
  class ValidationError < BasicError
6
- def initialize(msg, name, record)
6
+ def initialize(msg, name, model_instance)
7
7
  super(msg, name)
8
- raise 'Wrong record' unless record.respond_to?(:errors)
8
+ raise 'Wrong record' unless model_instance.respond_to?(:errors)
9
9
 
10
- @record = record
10
+ @model_instance = model_instance
11
11
  end
12
12
 
13
13
  def to_json(_options = nil)
@@ -20,15 +20,19 @@ module JsonErrors
20
20
 
21
21
  private
22
22
 
23
- attr_reader :record
23
+ attr_reader :model_instance
24
24
 
25
25
  def payload
26
- validation_payload = []
27
- record.errors.each do |error|
28
- validation_payload << { error.attribute => error.message }
26
+ validation_payload = model_instance.errors.map do |error|
27
+ {
28
+ 'object' => model_instance.class.to_s,
29
+ 'attribute' => error.attribute,
30
+ 'error_type' => error.type,
31
+ 'message' => error.full_message
32
+ }
29
33
  end
30
34
 
31
- { record.class.to_s => validation_payload }
35
+ { 'validation_errors' => validation_payload }
32
36
  end
33
37
  end
34
38
  end
@@ -4,11 +4,13 @@ module JsonErrors
4
4
  # Error facade
5
5
  class Error
6
6
  def self.method_missing(name, *args)
7
- message, payload = args
8
- return super unless name.in?(codes.keys)
7
+ error = args.first
8
+ payload = args.second
9
+ message = error.message
9
10
 
11
+ return super unless name.in?(codes.keys)
12
+ return ValidationError.new(message, name, error&.record) if codes[name][:validation_errors] == :active_record
10
13
  return BasicError.new(message, name) if payload.nil?
11
- return ValidationError.new(message, name, payload&.record) if codes[name][:validation_errors] == :active_record
12
14
 
13
15
  CustomPayloadError.new(message, name, payload)
14
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonErrors
4
- VERSION = '0.3.1'
4
+ VERSION = '0.3.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Łukasz Pająk
8
8
  - Nomtek
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-27 00:00:00.000000000 Z
11
+ date: 2025-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport