serega 0.14.0 → 0.16.0

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +85 -75
  3. data/VERSION +1 -1
  4. data/lib/serega/attribute.rb +2 -2
  5. data/lib/serega/attribute_normalizer.rb +8 -9
  6. data/lib/serega/config.rb +1 -1
  7. data/lib/serega/object_serializer.rb +1 -1
  8. data/lib/serega/plan.rb +11 -11
  9. data/lib/serega/plan_point.rb +5 -5
  10. data/lib/serega/plugins/activerecord_preloads/activerecord_preloads.rb +1 -1
  11. data/lib/serega/plugins/batch/batch.rb +15 -15
  12. data/lib/serega/plugins/batch/lib/validations/check_opt_batch.rb +2 -2
  13. data/lib/serega/plugins/camel_case/camel_case.rb +195 -0
  14. data/lib/serega/plugins/depth_limit/depth_limit.rb +185 -0
  15. data/lib/serega/plugins/explicit_many_option/explicit_many_option.rb +2 -5
  16. data/lib/serega/plugins/if/if.rb +4 -4
  17. data/lib/serega/plugins/metadata/metadata.rb +6 -6
  18. data/lib/serega/plugins/preloads/lib/modules/attribute_normalizer.rb +1 -1
  19. data/lib/serega/plugins/preloads/lib/preload_paths.rb +12 -5
  20. data/lib/serega/plugins/preloads/lib/preloads_constructor.rb +1 -1
  21. data/lib/serega/plugins/preloads/preloads.rb +12 -12
  22. data/lib/serega/plugins/root/root.rb +1 -1
  23. data/lib/serega/plugins/string_modifiers/string_modifiers.rb +1 -1
  24. data/lib/serega/validations/attribute/check_opt_const.rb +1 -1
  25. data/lib/serega/validations/attribute/check_opt_delegate.rb +9 -4
  26. data/lib/serega/validations/attribute/check_opt_many.rb +28 -11
  27. data/lib/serega/validations/attribute/{check_opt_key.rb → check_opt_method.rb} +8 -8
  28. data/lib/serega/validations/attribute/check_opt_value.rb +1 -1
  29. data/lib/serega/validations/check_attribute_params.rb +2 -2
  30. data/lib/serega/validations/check_initiate_params.rb +1 -1
  31. data/lib/serega/validations/check_serialize_params.rb +1 -1
  32. data/lib/serega/validations/utils/check_allowed_keys.rb +4 -2
  33. data/lib/serega.rb +24 -11
  34. metadata +5 -6
  35. data/lib/serega/plugins/openapi/lib/modules/config.rb +0 -23
  36. data/lib/serega/plugins/openapi/lib/openapi_config.rb +0 -101
  37. data/lib/serega/plugins/openapi/openapi.rb +0 -245
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f11821b5953500ef9f895ad8c96e97951734615363f3147c623b70519b6199a5
4
- data.tar.gz: 8b03241a9def2e5a8777a75e61062f8b81544e497a1a1e490e085d52f14a326c
3
+ metadata.gz: b291b12115b8ca239642972b103f896f13f02874acdc5663a8f404e02673ca8d
4
+ data.tar.gz: 18bd88ca4bd77ca147161189efe57b2c544da6cc1b460fc7c694855d4b22edc9
5
5
  SHA512:
6
- metadata.gz: eb5cb48e74c0e9c8307c6ceb6c47b918eb46ef3c160de90d0eb976239bbc036f1d3fb78219abd5567977f348e3e03d7e492e29140e6d85223fcf14289d794d89
7
- data.tar.gz: acb7623ea317aab640aae70d0a5dfa0c436b706529741b36b15d938ab6af7523576f72ab4633b591b61dcdc38df768818eab3811005c248c3a00d2872cdccc46
6
+ metadata.gz: d5c5114ed1c1b8b5a0714a340aca263983f5f8cdb24d15c8138124d64520ebafe03f6c64a7985f131ee399fab287ee578889b1affa1e2aa6f4ddacfbb9c8517e
7
+ data.tar.gz: 4d8191c7081b4650e3328141ec3cc2dc9128a7c4da3a38107e5f2c107d1d70446b67e718a3ffa2ff76e700f80dbdf975da9512d089c86ec552c3dc8a390345d1
data/README.md CHANGED
@@ -17,13 +17,16 @@ objects and to serialize them to Hash or JSON.
17
17
  It has some great features:
18
18
 
19
19
  - Manually [select serialized fields](#selecting-fields)
20
+ - Secure from malicious queries with [depth_limit][depth_limit] plugin
20
21
  - Solutions for N+1 problem (via [batch][batch], [preloads][preloads] or
21
22
  [activerecord_preloads][activerecord_preloads] plugins)
22
23
  - Built-in object presenter ([presenter][presenter] plugin)
23
24
  - Adding custom metadata (via [metadata][metadata] or
24
25
  [context_metadata][context_metadata] plugins)
25
- - Attributes formatters ([formatters][formatters] plugin)
26
- - Conditional attributes ([if][if] plugin)
26
+ - Value formatters ([formatters][formatters] plugin) helps to transform
27
+ time, date, money, percentage and any other values same way keeping code dry
28
+ - Conditional attributes - ([if][if] plugin)
29
+ - Auto camelCase keys - [camel_case][camel_case] plugin
27
30
 
28
31
  ## Installation
29
32
 
@@ -64,8 +67,8 @@ class UserSerializer < Serega
64
67
  # Regular attribute
65
68
  attribute :first_name
66
69
 
67
- # Option :key specifies method in object
68
- attribute :first_name, key: :old_first_name
70
+ # Option :method specifies method that must be called on serialized object
71
+ attribute :first_name, method: :old_first_name
69
72
 
70
73
  # Block is used to define attribute value
71
74
  attribute(:first_name) { |user| user.profile&.first_name }
@@ -77,8 +80,9 @@ class UserSerializer < Serega
77
80
  # Sub-option :allow_nil by default is false
78
81
  attribute :first_name, delegate: { to: :profile, allow_nil: true }
79
82
 
80
- # Option :delegate can be used with :key sub-option
81
- attribute :first_name, delegate: { to: :profile, key: :fname }
83
+ # Option :delegate can be used with :method sub-option, so method chain here
84
+ # is user.profile.fname
85
+ attribute :first_name, delegate: { to: :profile, method: :fname }
82
86
 
83
87
  # Option :const specifies attribute with specific constant value
84
88
  attribute(:type, const: 'user')
@@ -282,7 +286,7 @@ UserSerializer.to_h(bruce, with: fields_as_string)
282
286
 
283
287
  # With not existing attribute
284
288
  fields = %i[first_name enemy]
285
- fields_as_string = 'first_name,enemy')
289
+ fields_as_string = 'first_name,enemy'
286
290
  UserSerializer.new(only: fields).to_h(bruce)
287
291
  UserSerializer.to_h(bruce, only: fields)
288
292
  UserSerializer.to_h(bruce, only: fields_as_string)
@@ -433,7 +437,7 @@ end
433
437
  class UserSerializer < AppSerializer
434
438
  attribute :username
435
439
  attribute :user_stats,
436
- serializer: 'UserStatSerializer'
440
+ serializer: 'UserStatSerializer',
437
441
  value: proc { |user| user },
438
442
  preload: nil
439
443
  end
@@ -545,15 +549,15 @@ It can be used to find value for attributes in optimal way:
545
549
  After including plugin, attributes gain new `:batch` option:
546
550
 
547
551
  ```ruby
548
- attribute :name, batch: { key: :id, loader: :name_loader, default: nil }
552
+ attribute :name, batch: { loader: :name_loader, key: :id, default: nil }
549
553
  ```
550
554
 
551
555
  `:batch` option must be a hash with this keys:
552
556
 
553
- - `key` (required) [Symbol, Proc, callable] - Defines current object identifier.
554
- Later `loader` will accept array of `keys` to detect this keys values.
555
557
  - `loader` (required) [Symbol, Proc, callable] - Defines how to fetch values for
556
558
  batch of keys. Receives 3 parameters: keys, context, plan_point.
559
+ - `key` (required) [Symbol, Proc, callable] - Defines current object identifier.
560
+ Key is optional if plugin was defined with `default_key` option.
557
561
  - `default` (optional) - Default value for attribute.
558
562
  By default it is `nil` or `[]` when attribute has option `many: true`
559
563
  (ex: `attribute :tags, many: true, batch: { ... }`).
@@ -765,7 +769,7 @@ UserSerializer.to_h(nil, meta: { version: '1.0.1' })
765
769
 
766
770
  ### Plugin :formatters
767
771
 
768
- Allows to define `formatters` and apply them on attributes.
772
+ Allows to define `formatters` and apply them on attribute values.
769
773
 
770
774
  Config option `config.formatters.add` can be used to add formatters.
771
775
 
@@ -888,78 +892,86 @@ Look at [select serialized fields](#selecting-fields) for `:hide` usage examples
888
892
  end
889
893
  ```
890
894
 
891
- ### Plugin :openapi
895
+ ### Plugin :camel_case
896
+
897
+ By default when we add attribute like `attribute :first_name` this means:
898
+
899
+ - adding a `:first_name` key to resulted hash
900
+ - adding a `#first_name` method call result as value
892
901
 
893
- Helps to build OpenAPI schemas
902
+ But its often desired to response with *camelCased* keys.
903
+ By default this can be achieved by specifying attribute name and method directly
904
+ for each attribute: `attribute :firstName, method: first_name`
894
905
 
895
- This schemas can be easily used with [rswag](https://github.com/rswag/rswag#referenced-parameters-and-schema-definitions)"
896
- gem by adding them to "config.swagger_docs"
906
+ This plugin transforms all attribute names automatically.
907
+ We use simple regular expression to replace `_x` to `X` for the whole string.
908
+ We make this transformation only once when attribute is defined.
897
909
 
898
- Schemas properties will have no any "type" or other limits specified by default,
899
- you should provide them as new attribute `:openapi` option.
910
+ You can provide your own callable transformation when defining plugin,
911
+ for example `plugin :camel_case, transform: ->(name) { name.camelize }`
900
912
 
901
- This plugin adds type "object" or "array" only for relationships and marks
902
- attributes as **required** if they have no `:hide` option set
903
- (manually or automatically).
913
+ For any attribute camelCase-behavior can be skipped when
914
+ `camel_case: false` attribute option provided.
904
915
 
905
- After enabling this plugin attributes with :serializer option will have
906
- to have `:many` option set to construct "object" or "array" openapi
907
- property type.
916
+ This plugin transforms only attribute keys,
917
+ without affecting `root`, `metadata`, `context_metadata` plugins keys.
908
918
 
909
- - constructing all serializers schemas:
910
- `Serega::OpenAPI.schemas`
911
- - constructing specific serializers schemas:
912
- `Serega::OpenAPI.schemas(Serega::OpenAPI.serializers - [MyBaseSerializer])`
913
- - constructing one serializer schema:
914
- `SomeSerializer.openapi_schema`
919
+ If you wish to [select serialized fields](#selecting-fields), you should
920
+ provide them camelCased.
915
921
 
916
922
  ```ruby
917
- class BaseSerializer < Serega
918
- plugin :openapi
919
- end
923
+ class AppSerializer < Serega
924
+ plugin :camel_case
925
+ end
920
926
 
921
- class UserSerializer < BaseSerializer
922
- attribute :name, openapi: { type: "string" }
927
+ class UserSerializer < AppSerializer
928
+ attribute :first_name
929
+ attribute :last_name
930
+ attribute :full_name, camel_case: false,
931
+ value: proc { |user| [user.first_name, user.last_name].compact.join(" ") }
932
+ end
923
933
 
924
- openapi_properties(
925
- name: { type: :string }
926
- )
927
- end
934
+ require "ostruct"
935
+ user = OpenStruct.new(first_name: "Bruce", last_name: "Wayne")
936
+ UserSerializer.to_h(user)
937
+ # => {firstName: "Bruce", lastName: "Wayne", full_name: "Bruce Wayne"}
928
938
 
929
- class PostSerializer < BaseSerializer
930
- attribute :text, openapi: { type: "string" }
931
- attribute :user, serializer: UserSerializer, many: false
932
- attribute :comments, serializer: PostSerializer, many: true, hide: true
939
+ UserSerializer.new(only: %i[firstName lastName]).to_h(user)
940
+ # => {firstName: "Bruce", lastName: "Wayne"}
941
+ ```
933
942
 
934
- openapi_properties(
935
- text: { type: :string },
936
- user: { type: 'object' }, # `$ref` added automatically
937
- comments: { type: 'array' } # `items` option with `$ref` added automatically
938
- )
939
- end
943
+ ### Plugin :depth_limit
944
+
945
+ Helps to secure from malicious queries that require to serialize too much
946
+ or from accidental serializing of objects with cyclic relations.
947
+
948
+ Depth limit is checked when constructing a serialization plan, that is when
949
+ `#new` method is called, ex: `SomeSerializer.new(with: params[:with])`.
950
+ It can be useful to instantiate serializer before any other business logic
951
+ to get possible errors earlier.
952
+
953
+ Any class-level serialization methods also check depth limit as they also
954
+ instantiate serializer.
955
+
956
+ When depth limit is exceeded `Serega::DepthLimitError` is raised.
957
+ Depth limit error details can be found in additional
958
+ `Serega::DepthLimitError#details` method
959
+
960
+ Limit can be checked or changed with next config options:
961
+
962
+ - `config.depth_limit.limit`
963
+ - `config.depth_limit.limit=`
940
964
 
941
- puts Serega::OpenAPI.schemas
942
- # =>
943
- # {
944
- # "PostSerializer" => {
945
- # type: "object",
946
- # properties: {
947
- # text: {type: "string"},
948
- # user: {:$ref => "#/components/schemas/UserSerializer"},
949
- # comments: {type: "array", items: {:$ref => "#/components/schemas/PostSerializer"}}
950
- # },
951
- # required: [:text, :comments],
952
- # additionalProperties: false
953
- # },
954
- # "UserSerializer" => {
955
- # type: "object",
956
- # properties: {
957
- # name: {type: "string"}
958
- # },
959
- # required: [:name],
960
- # additionalProperties: false
961
- # }
962
- # }
965
+ There are no default limit, but it should be set when enabling plugin.
966
+
967
+ ```ruby
968
+ class AppSerializer < Serega
969
+ plugin :depth_limit, limit: 10 # set limit for all child classes
970
+ end
971
+
972
+ class UserSerializer < AppSerializer
973
+ config.depth_limit.limit = 5 # overrides limit for UserSerializer
974
+ end
963
975
  ```
964
976
 
965
977
  ### Plugin :explicit_many_option
@@ -967,12 +979,9 @@ property type.
967
979
  Plugin requires to add :many option when adding relationships
968
980
  (relationships are attributes with :serializer option specified)
969
981
 
970
- Adding this plugin makes clearer to find if relationship returns array or single
982
+ Adding this plugin makes it clearer to find if relationship returns array or single
971
983
  object
972
984
 
973
- Also plugin `:openapi` load this plugin automatically as it need to know if
974
- relationship is array
975
-
976
985
  ```ruby
977
986
  class BaseSerializer < Serega
978
987
  plugin :explicit_many_option
@@ -1018,6 +1027,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
1018
1027
 
1019
1028
  [activerecord_preloads]: #plugin-activerecord_preloads
1020
1029
  [batch]: #plugin-batch
1030
+ [camel_case]: #plugin-camel_case
1021
1031
  [context_metadata]: #plugin-context_metadata
1022
1032
  [formatters]: #plugin-formatters
1023
1033
  [metadata]: #plugin-metadata
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.14.0
1
+ 0.16.0
@@ -22,7 +22,7 @@ class Serega
22
22
  attr_reader :many
23
23
 
24
24
  # Attribute :hide option
25
- # @return [Boolean nil] Attribute :hide option
25
+ # @return [Boolean, nil] Attribute :hide option
26
26
  attr_reader :hide
27
27
 
28
28
  #
@@ -30,7 +30,7 @@ class Serega
30
30
  #
31
31
  # @param name [Symbol, String] Name of attribute
32
32
  # @param opts [Hash] Attribute options
33
- # @option opts [Symbol] :key Object method name to fetch attribute value
33
+ # @option opts [Symbol] :method Object method name to fetch attribute value
34
34
  # @option opts [Hash] :delegate Allows to fetch value from nested object
35
35
  # @option opts [Boolean] :hide Specify `true` to not serialize this attribute by default
36
36
  # @option opts [Boolean] :many Specifies has_many relationship. By default is detected via object.is_a?(Enumerable)
@@ -36,12 +36,12 @@ class Serega
36
36
  end
37
37
 
38
38
  #
39
- # Symbolized initial attribute key or attribute name if key is empty
39
+ # Symbolized initial attribute method name
40
40
  #
41
- # @return [Symbol] Attribute normalized name
41
+ # @return [Symbol] Attribute normalized method name
42
42
  #
43
- def key
44
- @key ||= prepare_key
43
+ def method_name
44
+ @method_name ||= prepare_method_name
45
45
  end
46
46
 
47
47
  #
@@ -121,9 +121,8 @@ class Serega
121
121
  init_opts[:serializer]
122
122
  end
123
123
 
124
- def prepare_key
125
- key = init_opts[:key]
126
- key ? key.to_sym : name
124
+ def prepare_method_name
125
+ (init_opts[:method] || init_name).to_sym
127
126
  end
128
127
 
129
128
  def prepare_const_block
@@ -134,7 +133,7 @@ class Serega
134
133
  end
135
134
 
136
135
  def prepare_keyword_block
137
- key_method_name = key
136
+ key_method_name = method_name
138
137
  proc do |object|
139
138
  object.public_send(key_method_name)
140
139
  end
@@ -144,7 +143,7 @@ class Serega
144
143
  delegate = init_opts[:delegate]
145
144
  return unless delegate
146
145
 
147
- key_method_name = delegate[:key] || key
146
+ key_method_name = delegate[:method] || method_name
148
147
  delegate_to = delegate[:to]
149
148
 
150
149
  allow_nil = delegate.fetch(:allow_nil) { self.class.serializer_class.config.delegate_default_allow_nil }
data/lib/serega/config.rb CHANGED
@@ -15,7 +15,7 @@ class Serega
15
15
  DEFAULTS = {
16
16
  plugins: [],
17
17
  initiate_keys: %i[only with except check_initiate_params].freeze,
18
- attribute_keys: %i[key value serializer many hide const delegate].freeze,
18
+ attribute_keys: %i[method value serializer many hide const delegate].freeze,
19
19
  serialize_keys: %i[context many].freeze,
20
20
  check_attribute_name: true,
21
21
  check_initiate_params: true,
@@ -14,7 +14,7 @@ class Serega
14
14
 
15
15
  # @param plan [SeregaPlan] Serialization plan
16
16
  # @param context [Hash] Serialization context
17
- # @param many [TrueClass|FalseClass] is object is enumerable
17
+ # @param many [Boolean] is object is enumerable
18
18
  # @param opts [Hash] Any custom options
19
19
  #
20
20
  # @return [SeregaObjectSerializer] New SeregaObjectSerializer
data/lib/serega/plan.rb CHANGED
@@ -22,7 +22,7 @@ class Serega
22
22
  #
23
23
  def call(opts)
24
24
  max_cache_size = serializer_class.config.max_cached_plans_per_serializer_count
25
- return new(opts) if max_cache_size.zero?
25
+ return new(nil, opts) if max_cache_size.zero?
26
26
 
27
27
  cached_plan_for(opts, max_cache_size)
28
28
  end
@@ -33,7 +33,7 @@ class Serega
33
33
  @cache ||= {}
34
34
  cache_key = construct_cache_key(opts)
35
35
 
36
- plan = @cache[cache_key] ||= new(opts)
36
+ plan = @cache[cache_key] ||= new(nil, opts)
37
37
  @cache.shift if @cache.length > max_cache_size
38
38
  plan
39
39
  end
@@ -61,25 +61,26 @@ class Serega
61
61
  # @return [SeregaPlanPoint, nil]
62
62
  attr_reader :parent_plan_point
63
63
 
64
- # Sets new parent plan point
65
- # @return [SeregaPlanPoint] new parent plan point
66
- attr_writer :parent_plan_point
67
-
68
64
  # Serialization points
69
65
  # @return [Array<SeregaPlanPoint>] points to serialize
70
66
  attr_reader :points
71
67
 
72
68
  #
73
- # Instantiate new serialization plan.
69
+ # Instantiate new serialization plan
70
+ #
71
+ # Patched by
72
+ # - depth_limit plugin, which checks depth limit is not exceeded when adding new plan
74
73
  #
75
- # @param modifiers Serialization parameters
74
+ # @param parent_plan_point [SeregaPlanPoint, nil] Parent plan_point
75
+ # @param modifiers [Hash] Serialization parameters
76
76
  # @option modifiers [Hash] :only The only attributes to serialize
77
77
  # @option modifiers [Hash] :except Attributes to hide
78
78
  # @option modifiers [Hash] :with Hidden attributes to serialize additionally
79
79
  #
80
80
  # @return [SeregaPlan] Serialization plan
81
81
  #
82
- def initialize(modifiers)
82
+ def initialize(parent_plan_point, modifiers)
83
+ @parent_plan_point = parent_plan_point
83
84
  @points = attributes_points(modifiers)
84
85
  end
85
86
 
@@ -107,8 +108,7 @@ class Serega
107
108
  {only: only[name], with: with[name], except: except[name]}
108
109
  end
109
110
 
110
- point = serializer_class::SeregaPlanPoint.new(attribute, child_fields)
111
- point.plan = self
111
+ point = serializer_class::SeregaPlanPoint.new(self, attribute, child_fields)
112
112
  points << point.freeze
113
113
  end
114
114
 
@@ -13,7 +13,7 @@ class Serega
13
13
 
14
14
  # Link to current plan this point belongs to
15
15
  # @return [SeregaAttribute] Current plan
16
- attr_accessor :plan
16
+ attr_reader :plan
17
17
 
18
18
  # Shows current attribute
19
19
  # @return [SeregaAttribute] Current attribute
@@ -44,6 +44,7 @@ class Serega
44
44
  #
45
45
  # Initializes plan point
46
46
  #
47
+ # @param plan [SeregaPlan] Current plan this point belongs to
47
48
  # @param attribute [SeregaAttribute] Attribute to construct plan point
48
49
  # @param modifiers Serialization parameters
49
50
  # @option modifiers [Hash] :only The only attributes to serialize
@@ -52,7 +53,8 @@ class Serega
52
53
  #
53
54
  # @return [SeregaPlanPoint] New plan point
54
55
  #
55
- def initialize(attribute, modifiers = nil)
56
+ def initialize(plan, attribute, modifiers = nil)
57
+ @plan = plan
56
58
  @attribute = attribute
57
59
  @modifiers = modifiers
58
60
  set_normalized_vars
@@ -79,9 +81,7 @@ class Serega
79
81
 
80
82
  fields = modifiers || FROZEN_EMPTY_HASH
81
83
 
82
- plan = serializer::SeregaPlan.new(fields)
83
- plan.parent_plan_point = self
84
- plan
84
+ serializer::SeregaPlan.new(self, fields)
85
85
  end
86
86
  end
87
87
 
@@ -77,7 +77,7 @@ class Serega
77
77
  # @return [void]
78
78
  #
79
79
  def self.load_plugin(serializer_class, **_opts)
80
- require_relative "./lib/preloader"
80
+ require_relative "lib/preloader"
81
81
 
82
82
  serializer_class.include(InstanceMethods)
83
83
  end
@@ -79,18 +79,18 @@ class Serega
79
79
  # @return [void]
80
80
  #
81
81
  def self.load_plugin(serializer_class, **_opts)
82
- require_relative "./lib/batch_config"
83
- require_relative "./lib/loader"
84
- require_relative "./lib/loaders"
85
- require_relative "./lib/modules/attribute"
86
- require_relative "./lib/modules/attribute_normalizer"
87
- require_relative "./lib/modules/check_attribute_params"
88
- require_relative "./lib/modules/config"
89
- require_relative "./lib/modules/object_serializer"
90
- require_relative "./lib/modules/plan_point"
91
- require_relative "./lib/validations/check_batch_opt_key"
92
- require_relative "./lib/validations/check_batch_opt_loader"
93
- require_relative "./lib/validations/check_opt_batch"
82
+ require_relative "lib/batch_config"
83
+ require_relative "lib/loader"
84
+ require_relative "lib/loaders"
85
+ require_relative "lib/modules/attribute"
86
+ require_relative "lib/modules/attribute_normalizer"
87
+ require_relative "lib/modules/check_attribute_params"
88
+ require_relative "lib/modules/config"
89
+ require_relative "lib/modules/object_serializer"
90
+ require_relative "lib/modules/plan_point"
91
+ require_relative "lib/validations/check_batch_opt_key"
92
+ require_relative "lib/validations/check_batch_opt_loader"
93
+ require_relative "lib/validations/check_opt_batch"
94
94
 
95
95
  serializer_class.extend(ClassMethods)
96
96
  serializer_class.include(InstanceMethods)
@@ -121,18 +121,18 @@ class Serega
121
121
  serializer_class.const_set(:SeregaBatchLoader, batch_loader_class)
122
122
 
123
123
  if serializer_class.plugin_used?(:activerecord_preloads)
124
- require_relative "./lib/plugins_extensions/activerecord_preloads"
124
+ require_relative "lib/plugins_extensions/activerecord_preloads"
125
125
  serializer_class::SeregaBatchLoader.include(PluginsExtensions::ActiveRecordPreloads::BatchLoaderInstanceMethods)
126
126
  end
127
127
 
128
128
  if serializer_class.plugin_used?(:formatters)
129
- require_relative "./lib/plugins_extensions/formatters"
129
+ require_relative "lib/plugins_extensions/formatters"
130
130
  serializer_class::SeregaBatchLoader.include(PluginsExtensions::Formatters::BatchLoaderInstanceMethods)
131
131
  serializer_class::SeregaAttribute.include(PluginsExtensions::Formatters::SeregaAttributeInstanceMethods)
132
132
  end
133
133
 
134
134
  if serializer_class.plugin_used?(:preloads)
135
- require_relative "./lib/plugins_extensions/preloads"
135
+ require_relative "lib/plugins_extensions/preloads"
136
136
  serializer_class::SeregaAttributeNormalizer.include(PluginsExtensions::Preloads::AttributeNormalizerInstanceMethods)
137
137
  end
138
138
 
@@ -23,7 +23,7 @@ class Serega
23
23
  SeregaValidations::Utils::CheckOptIsHash.call(opts, :batch)
24
24
 
25
25
  batch = opts[:batch]
26
- SeregaValidations::Utils::CheckAllowedKeys.call(batch, %i[key loader default])
26
+ SeregaValidations::Utils::CheckAllowedKeys.call(batch, %i[key loader default], :batch)
27
27
 
28
28
  check_batch_opt_key(batch, serializer_class)
29
29
  check_batch_opt_loader(batch)
@@ -50,7 +50,7 @@ class Serega
50
50
  end
51
51
 
52
52
  def check_usage_with_other_params(opts, block)
53
- raise SeregaError, "Option :batch can not be used together with option :key" if opts.key?(:key)
53
+ raise SeregaError, "Option :batch can not be used together with option :method" if opts.key?(:method)
54
54
  raise SeregaError, "Option :batch can not be used together with option :value" if opts.key?(:value)
55
55
  raise SeregaError, "Option :batch can not be used together with option :const" if opts.key?(:const)
56
56
  raise SeregaError, "Option :batch can not be used together with option :delegate" if opts.key?(:delegate)