File tree 7 files changed +48
-40
lines changed
7 files changed +48
-40
lines changed Original file line number Diff line number Diff line change 1
- --format documentation
1
+ --format progress
2
+ --warnings
2
3
--color
3
4
--require spec_helper
Original file line number Diff line number Diff line change
1
+ ## [ 0.1.6] - 2025-02-04
2
+
3
+ - Move ` Validations::Message ` to inside HeavyKeeper namespace to avoid
4
+ conflict
5
+
1
6
## [ 0.1.5] - 2024-06-13
2
7
3
8
- Support latest version of xx-hash
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ gem 'rake', '~> 13.0'
11
11
gem 'redis', '~> 4.0'
12
12
13
13
group :test do
14
- gem 'mock_redis'
14
+ gem 'mock_redis', '< 0.47.0'
15
15
gem 'rspec'
16
16
gem 'pry-byebug'
17
17
end
Original file line number Diff line number Diff line change 3
3
require 'dry-schema'
4
4
require 'securerandom'
5
5
require 'xxhash'
6
- require_relative '../ validations/message'
6
+ require_relative 'validations/message'
7
7
8
8
module HeavyKeeper
9
9
class TopK # rubocop:disable Metrics/ClassLength
@@ -217,7 +217,7 @@ def validate(options)
217
217
result = Validator . call ( options )
218
218
219
219
if result . failure?
220
- error = :: Validations ::Message . new . build ( result . errors . to_h ) . join ( '. ' )
220
+ error = Validations ::Message . new . build ( result . errors . to_h ) . join ( '. ' )
221
221
raise HeavyKeeper ::Error , error
222
222
end
223
223
Original file line number Diff line number Diff line change
1
+ module HeavyKeeper
2
+ module Validations
3
+ class Message
4
+ CLASSIFY_SEPARATOR = '_' . freeze
5
+ TITLEIZE_SEPARATOR = ' ' . freeze
6
+
7
+ # @errors [Hash | Array] output of dry-validation
8
+ # after validating params
9
+ # @parent [Nil | String] key name of a field that has `errors`
10
+ # after validating params
11
+ # Output: array of string that can be used to feed into
12
+ # Errors::InvalidParamsError
13
+ def build ( errors , parent = nil )
14
+ case errors
15
+ when Hash
16
+ errors . flat_map do |key , value |
17
+ child = [ parent , key ] . compact . join ( ' ' )
18
+ build ( value , child )
19
+ end
20
+ when Array
21
+ errors . flat_map do |error |
22
+ "#{ titleize ( parent . to_s ) } #{ build ( error ) } "
23
+ end
24
+ else
25
+ errors
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def titleize ( string )
32
+ # NOTE: this is not a robust implementation of titleize
33
+ string . split ( CLASSIFY_SEPARATOR ) . map ( &:capitalize ) . join ( TITLEIZE_SEPARATOR )
34
+ end
35
+ end
36
+ end
37
+ end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
module HeavyKeeper
4
- VERSION = '0.1.5 '
4
+ VERSION = '0.1.6 '
5
5
end
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments