serega 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -10
  3. data/VERSION +1 -1
  4. data/lib/serega/attribute.rb +3 -3
  5. data/lib/serega/attribute_normalizer.rb +21 -2
  6. data/lib/serega/plugins/batch/lib/batch_config.rb +11 -8
  7. data/lib/serega/plugins/batch/lib/modules/attribute_normalizer.rb +26 -11
  8. data/lib/serega/plugins/batch/lib/validations/check_batch_opt_key.rb +5 -35
  9. data/lib/serega/plugins/batch/lib/validations/check_batch_opt_loader.rb +5 -35
  10. data/lib/serega/plugins/formatters/formatters.rb +88 -14
  11. data/lib/serega/plugins/if/if.rb +43 -19
  12. data/lib/serega/plugins/if/validations/check_opt_if.rb +4 -36
  13. data/lib/serega/plugins/if/validations/check_opt_if_value.rb +7 -39
  14. data/lib/serega/plugins/if/validations/check_opt_unless.rb +4 -45
  15. data/lib/serega/plugins/if/validations/check_opt_unless_value.rb +7 -39
  16. data/lib/serega/plugins/metadata/meta_attribute.rb +21 -5
  17. data/lib/serega/plugins/metadata/metadata.rb +16 -7
  18. data/lib/serega/plugins/metadata/validations/check_block.rb +10 -10
  19. data/lib/serega/plugins/metadata/validations/check_opt_const.rb +38 -0
  20. data/lib/serega/plugins/metadata/validations/check_opt_value.rb +61 -0
  21. data/lib/serega/plugins/metadata/validations/check_opts.rb +24 -10
  22. data/lib/serega/utils/params_count.rb +50 -0
  23. data/lib/serega/utils/to_hash.rb +1 -1
  24. data/lib/serega/validations/attribute/check_block.rb +4 -5
  25. data/lib/serega/validations/attribute/check_opt_value.rb +16 -12
  26. data/lib/serega/validations/check_attribute_params.rb +1 -0
  27. data/lib/serega/validations/utils/check_extra_keyword_arg.rb +33 -0
  28. data/lib/serega.rb +2 -0
  29. metadata +7 -3
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Serega
4
+ module SeregaValidations
5
+ #
6
+ # Validations Utilities
7
+ #
8
+ module Utils
9
+ #
10
+ # Utility to check that callable object has no required keyword arguments
11
+ #
12
+ class CheckExtraKeywordArg
13
+ # Checks hash keys are allowed
14
+ #
15
+ # @param callable [#call] Callable object
16
+ # @param callable_description [Symbol] Callable object description
17
+ #
18
+ # @raise [Serega::SeregaError] error if callable accepts required keyword argument
19
+ #
20
+ # @return [void]
21
+ def self.call(callable, callable_description)
22
+ parameters = callable.is_a?(Proc) ? callable.parameters : callable.method(:call).parameters
23
+
24
+ parameters.each do |parameter|
25
+ next unless parameter[0] == :keyreq
26
+
27
+ raise Serega::SeregaError, "Invalid #{callable_description}. It should not have any required keyword arguments"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
data/lib/serega.rb CHANGED
@@ -17,6 +17,7 @@ require_relative "serega/errors"
17
17
  require_relative "serega/helpers/serializer_class_helper"
18
18
  require_relative "serega/utils/enum_deep_dup"
19
19
  require_relative "serega/utils/enum_deep_freeze"
20
+ require_relative "serega/utils/params_count"
20
21
  require_relative "serega/utils/symbol_name"
21
22
  require_relative "serega/utils/to_hash"
22
23
  require_relative "serega/json/adapter"
@@ -24,6 +25,7 @@ require_relative "serega/json/adapter"
24
25
  require_relative "serega/attribute"
25
26
  require_relative "serega/attribute_normalizer"
26
27
  require_relative "serega/validations/utils/check_allowed_keys"
28
+ require_relative "serega/validations/utils/check_extra_keyword_arg"
27
29
  require_relative "serega/validations/utils/check_opt_is_bool"
28
30
  require_relative "serega/validations/utils/check_opt_is_hash"
29
31
  require_relative "serega/validations/utils/check_opt_is_string_or_symbol"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serega
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Glushkov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-14 00:00:00.000000000 Z
11
+ date: 2023-11-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  JSON Serializer
@@ -72,8 +72,10 @@ files:
72
72
  - lib/serega/plugins/metadata/meta_attribute.rb
73
73
  - lib/serega/plugins/metadata/metadata.rb
74
74
  - lib/serega/plugins/metadata/validations/check_block.rb
75
+ - lib/serega/plugins/metadata/validations/check_opt_const.rb
75
76
  - lib/serega/plugins/metadata/validations/check_opt_hide_empty.rb
76
77
  - lib/serega/plugins/metadata/validations/check_opt_hide_nil.rb
78
+ - lib/serega/plugins/metadata/validations/check_opt_value.rb
77
79
  - lib/serega/plugins/metadata/validations/check_opts.rb
78
80
  - lib/serega/plugins/metadata/validations/check_path.rb
79
81
  - lib/serega/plugins/preloads/lib/format_user_preloads.rb
@@ -94,6 +96,7 @@ files:
94
96
  - lib/serega/plugins/string_modifiers/string_modifiers.rb
95
97
  - lib/serega/utils/enum_deep_dup.rb
96
98
  - lib/serega/utils/enum_deep_freeze.rb
99
+ - lib/serega/utils/params_count.rb
97
100
  - lib/serega/utils/symbol_name.rb
98
101
  - lib/serega/utils/to_hash.rb
99
102
  - lib/serega/validations/attribute/check_block.rb
@@ -110,6 +113,7 @@ files:
110
113
  - lib/serega/validations/check_serialize_params.rb
111
114
  - lib/serega/validations/initiate/check_modifiers.rb
112
115
  - lib/serega/validations/utils/check_allowed_keys.rb
116
+ - lib/serega/validations/utils/check_extra_keyword_arg.rb
113
117
  - lib/serega/validations/utils/check_opt_is_bool.rb
114
118
  - lib/serega/validations/utils/check_opt_is_hash.rb
115
119
  - lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
@@ -136,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
140
  - !ruby/object:Gem::Version
137
141
  version: '0'
138
142
  requirements: []
139
- rubygems_version: 3.4.6
143
+ rubygems_version: 3.4.21
140
144
  signing_key:
141
145
  specification_version: 4
142
146
  summary: JSON Serializer