serega 0.40.0 → 0.40.1

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +21 -0
  3. data/README.md +90 -107
  4. data/VERSION +1 -1
  5. data/lib/serega/attribute.rb +2 -0
  6. data/lib/serega/attribute_normalizer.rb +2 -0
  7. data/lib/serega/attribute_value_resolvers/batch.rb +3 -0
  8. data/lib/serega/attribute_value_resolvers/const.rb +3 -0
  9. data/lib/serega/attribute_value_resolvers/delegate.rb +4 -0
  10. data/lib/serega/attribute_value_resolvers/hash_access.rb +6 -0
  11. data/lib/serega/attribute_value_resolvers/keyword.rb +3 -0
  12. data/lib/serega/data_builder.rb +2 -0
  13. data/lib/serega/engine/level.rb +2 -0
  14. data/lib/serega/engine/level_queue.rb +2 -0
  15. data/lib/serega/engine/loader.rb +3 -0
  16. data/lib/serega/helpers/serializer_class_helper.rb +2 -0
  17. data/lib/serega/object_serializer.rb +2 -0
  18. data/lib/serega/plan.rb +3 -0
  19. data/lib/serega/plan_point.rb +2 -0
  20. data/lib/serega/plugins/activerecord_preloads/activerecord_preloads.rb +22 -16
  21. data/lib/serega/plugins/activerecord_preloads/lib/preloader.rb +6 -0
  22. data/lib/serega/plugins/camel_case/camel_case.rb +13 -13
  23. data/lib/serega/plugins/context_metadata/context_metadata.rb +8 -1
  24. data/lib/serega/plugins/depth_limit/depth_limit.rb +15 -12
  25. data/lib/serega/plugins/explicit_many_option/explicit_many_option.rb +12 -10
  26. data/lib/serega/plugins/explicit_many_option/validations/check_opt_many.rb +1 -0
  27. data/lib/serega/plugins/formatters/formatters.rb +18 -10
  28. data/lib/serega/plugins/if/if.rb +29 -32
  29. data/lib/serega/plugins/if/validations/check_opt_if.rb +1 -0
  30. data/lib/serega/plugins/if/validations/check_opt_if_value.rb +1 -0
  31. data/lib/serega/plugins/if/validations/check_opt_unless.rb +1 -0
  32. data/lib/serega/plugins/if/validations/check_opt_unless_value.rb +1 -0
  33. data/lib/serega/plugins/metadata/meta_attribute.rb +2 -0
  34. data/lib/serega/plugins/metadata/metadata.rb +14 -12
  35. data/lib/serega/plugins/metadata/validations/check_block.rb +1 -0
  36. data/lib/serega/plugins/metadata/validations/check_opt_const.rb +1 -0
  37. data/lib/serega/plugins/metadata/validations/check_opt_hide_empty.rb +1 -0
  38. data/lib/serega/plugins/metadata/validations/check_opt_hide_nil.rb +1 -0
  39. data/lib/serega/plugins/metadata/validations/check_opt_value.rb +1 -0
  40. data/lib/serega/plugins/metadata/validations/check_opts.rb +1 -0
  41. data/lib/serega/plugins/metadata/validations/check_path.rb +1 -0
  42. data/lib/serega/plugins/presenter/presenter.rb +10 -7
  43. data/lib/serega/plugins/root/root.rb +10 -6
  44. data/lib/serega/plugins/string_modifiers/parse_string_modifiers.rb +1 -0
  45. data/lib/serega/plugins/string_modifiers/string_modifiers.rb +21 -0
  46. data/lib/serega/plugins.rb +2 -0
  47. data/lib/serega/utils/collection_detector.rb +2 -0
  48. data/lib/serega/utils/enum_deep_dup.rb +2 -0
  49. data/lib/serega/utils/enum_deep_freeze.rb +2 -0
  50. data/lib/serega/utils/method_signature.rb +2 -0
  51. data/lib/serega/utils/serialized_attribute_error.rb +2 -0
  52. data/lib/serega/utils/symbol_name.rb +2 -0
  53. data/lib/serega/utils/to_hash.rb +2 -0
  54. data/lib/serega/validations/attribute/check_block.rb +3 -0
  55. data/lib/serega/validations/attribute/check_name.rb +3 -0
  56. data/lib/serega/validations/attribute/check_opt_base_serializer.rb +3 -0
  57. data/lib/serega/validations/attribute/check_opt_batch.rb +3 -0
  58. data/lib/serega/validations/attribute/check_opt_const.rb +3 -0
  59. data/lib/serega/validations/attribute/check_opt_delegate.rb +3 -0
  60. data/lib/serega/validations/attribute/check_opt_hash_access.rb +3 -0
  61. data/lib/serega/validations/attribute/check_opt_hide.rb +3 -0
  62. data/lib/serega/validations/attribute/check_opt_many.rb +3 -0
  63. data/lib/serega/validations/attribute/check_opt_method.rb +3 -0
  64. data/lib/serega/validations/attribute/check_opt_preload.rb +3 -0
  65. data/lib/serega/validations/attribute/check_opt_serializer.rb +3 -0
  66. data/lib/serega/validations/attribute/check_opt_value.rb +3 -0
  67. data/lib/serega/validations/check_attribute_params.rb +3 -0
  68. data/lib/serega/validations/check_batch_loader_params.rb +3 -0
  69. data/lib/serega/validations/check_initiate_params.rb +3 -0
  70. data/lib/serega/validations/check_serialize_params.rb +3 -0
  71. data/lib/serega/validations/initiate/check_modifiers.rb +3 -0
  72. data/lib/serega/validations/utils/check_allowed_keys.rb +3 -0
  73. data/lib/serega/validations/utils/check_opt_is_bool.rb +3 -0
  74. data/lib/serega/validations/utils/check_opt_is_hash.rb +3 -0
  75. data/lib/serega/validations/utils/check_opt_is_string_or_symbol.rb +3 -0
  76. data/lib/serega.rb +6 -0
  77. metadata +13 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42da0ff66dc5eeb282fbb72144f78bcfc8ded1aa8609122ded10093f6c83dd96
4
- data.tar.gz: f9fb2a2628756540cd08a5449a21883b0cf28ec45db8f461ee0944fd0f3812e9
3
+ metadata.gz: edecae0c35540be687e394092e3b0a158fa1c2aeff4710ff5ce8e17effba1eb2
4
+ data.tar.gz: 7e63d238aad501f31be388824bb6b594e9f7988e17c49e4fc478d9353993c63b
5
5
  SHA512:
6
- metadata.gz: 1355573b7cb8d30ffbf844be46c03c4a5233fa9c190fa5e03fd39c0d1a396b9f7a19e7e2d4cf3afbd0445cd1d8dfc8ebbd1df6d77d91d338c0ede561c836fb99
7
- data.tar.gz: 90ccd454b970598f9921ec1a6c9feab325a373d5628f884515141d34a3a72e7012273e37aa903046e064876f92bd956783ef3a9b93732ee23a8bcc8bec154ee3
6
+ metadata.gz: 506607362308145ffcc0a34474d76d8b0a0edb7fbb570deb1fb973c71c396aab65a1b7b408069d31c8a5e15f8c8146316f835194c53e4a68315fe62eb4992421
7
+ data.tar.gz: 6d5b5ebe921a36b197b4829721af89eb92f5e47522101d126cffc8c72e30ad2679a6f9084df2685cf2250d772c5b0974b76861260b2eb19c6f53660fba16f5d4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Andrey Glushkov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -4,7 +4,8 @@
4
4
  [![GitHub Actions][build-badge]][build]
5
5
 
6
6
  The Serega Ruby Serializer provides easy and powerful DSL to describe your
7
- objects and serialize them to Hash or JSON.
7
+ objects and serialize them to Hash, ready for further conversion to JSON or
8
+ other formats.
8
9
 
9
10
  ---
10
11
 
@@ -749,31 +750,38 @@ handler; to use a different ORM, register your own instead.
749
750
  ```ruby
750
751
  class AppSerializer < Serega
751
752
  config.auto_preload = true
752
- config.hide_by_default = false
753
-
754
753
  plugin :activerecord_preloads
755
754
  end
756
755
 
756
+ class AlbumSerializer < AppSerializer
757
+ # no preloads
758
+ attribute :title
759
+
760
+ # preloads :downloads, as manually specified
761
+ attribute :downloads_count, preload: :downloads, value: proc { |album| album.downloads.count }
762
+ end
763
+
757
764
  class UserSerializer < AppSerializer
765
+ # no preloads
758
766
  attribute :username
767
+
768
+ # preloads :user_stats, as auto_preload is enabled for :delegate attributes
759
769
  attribute :comments_count, delegate: { to: :user_stats }
760
- attribute :albums, serializer: AlbumSerializer
761
- end
762
770
 
763
- class AlbumSerializer < AppSerializer
764
- attribute :title
765
- attribute :downloads_count, preload: :downloads,
766
- value: proc { |album| album.downloads.count }
771
+ # preloads :albums, as auto_preload is enabled for :serializer attributes
772
+ attribute :albums, serializer: AlbumSerializer
767
773
  end
768
774
 
769
- UserSerializer.to_h(user)
770
- # preloads :user_stats and :albums on the user; the AlbumSerializer level
771
- # preloads :downloads on the albums
775
+ UserSerializer.to_h(users)
776
+ # 1 query to load :user_stats for all users
777
+ # + 1 query to load :albums for all users
778
+ # + 1 query to load :downloads for all albums
779
+ # = 3 queries total, regardless of how many users/albums are serialized
772
780
  ```
773
781
 
774
782
  ### Plugin :root
775
783
 
776
- Allows to add root key to your serialized data
784
+ Adds a root key to serialized data.
777
785
 
778
786
  Accepts options:
779
787
 
@@ -786,56 +794,47 @@ Adds additional config options:
786
794
  - config.root.one
787
795
  - config.root.many
788
796
  - config.root.one=
789
- - config.root_many=
797
+ - config.root.many=
790
798
 
791
799
  The default root is `:data`.
792
800
 
793
- The root key can be changed per serialization.
794
-
795
801
  ```ruby
796
- # @example Change root per serialization:
802
+ class UserSerializer < Serega
803
+ plugin :root # default root is :data
804
+ end
797
805
 
798
- class UserSerializer < Serega
799
- plugin :root
800
- end
806
+ class UserSerializer < Serega
807
+ plugin :root, root: :users
808
+ end
801
809
 
802
- UserSerializer.to_h(nil) # => {:data=>nil}
803
- UserSerializer.to_h(nil, root: :user) # => {:user=>nil}
804
- UserSerializer.to_h(nil, root: nil) # => nil
805
- ```
810
+ class UserSerializer < Serega
811
+ plugin :root, root_one: :user, root_many: :people
812
+ end
806
813
 
807
- The root key can be removed for all responses by providing the `root: nil`
808
- plugin option.
814
+ class UserSerializer < Serega
815
+ plugin :root, root: nil # no root key by default
816
+ end
817
+ ```
809
818
 
810
- In this case, no root key will be added. But it still can be added manually.
819
+ The root key can also be changed per serialization, or removed entirely by
820
+ providing `root: nil` (it can still be added back per serialization).
811
821
 
812
822
  ```ruby
813
- #@example Define :root plugin with different options
814
-
815
- class UserSerializer < Serega
816
- plugin :root # default root is :data
817
- end
818
-
819
- class UserSerializer < Serega
820
- plugin :root, root: :users
821
- end
822
-
823
- class UserSerializer < Serega
824
- plugin :root, root_one: :user, root_many: :people
825
- end
823
+ class UserSerializer < Serega
824
+ plugin :root
825
+ end
826
826
 
827
- class UserSerializer < Serega
828
- plugin :root, root: nil # no root key by default
829
- end
827
+ UserSerializer.to_h(nil) # => {:data=>nil}
828
+ UserSerializer.to_h(nil, root: :user) # => {:user=>nil}
829
+ UserSerializer.to_h(nil, root: nil) # => nil
830
830
  ```
831
831
 
832
832
  ### Plugin :metadata
833
833
 
834
834
  Depends on: [`:root`][root] plugin, that must be loaded first
835
835
 
836
- Adds ability to describe metadata and adds it to serialized response
837
-
838
- Adds class-level `.meta_attribute` method. It accepts:
836
+ Adds metadata to the serialized response via the class-level `meta_attribute`
837
+ method, which accepts:
839
838
 
840
839
  - `*path` [Array of Symbols] - nested hash keys.
841
840
  - `**options` [Hash]
@@ -875,7 +874,8 @@ AppSerializer.to_h(nil)
875
874
 
876
875
  Depends on: [`:root`][root] plugin, that must be loaded first
877
876
 
878
- Allows to provide metadata and attach it to serialized response.
877
+ Adds metadata supplied per serialization call (as opposed to `:metadata`,
878
+ which is defined statically on the serializer).
879
879
 
880
880
  Accepts option `:context_metadata_key` with the name of the root metadata keyword.
881
881
  By default, it has the `:meta` value.
@@ -899,41 +899,39 @@ UserSerializer.to_h(nil, meta: { version: '1.0.1' })
899
899
 
900
900
  ### Plugin :formatters
901
901
 
902
- Allows to define `formatters` and apply them to attribute values.
902
+ Defines named value formatters once and applies them to any attribute.
903
903
 
904
- Config option `config.formatters.add` can be used to add formatters.
904
+ Use `config.formatters.add()` to register formatters. The `:format`
905
+ attribute option then accepts a formatter name or a callable directly.
905
906
 
906
- Attribute option `:format` can be used with the name of formatter or with
907
- callable instance.
908
-
909
- Formatters can accept up to 2 parameters (formatted object, context)
907
+ Formatters receive up to 2 parameters: the value and the context.
910
908
 
911
909
  ```ruby
912
910
  class AppSerializer < Serega
913
911
  plugin :formatters, formatters: {
914
- iso8601: ->(value) { time.iso8601.round(6) },
912
+ iso8601: ->(value) { value.iso8601 },
915
913
  on_off: ->(value) { value ? 'ON' : 'OFF' },
916
- money: ->(value, ctx) { value / 10**ctx[:digits) }
914
+ money: ->(value) { value.round(2) },
917
915
  date: DateTypeFormatter # callable
918
916
  }
919
917
  end
920
918
 
921
919
  class UserSerializer < Serega
922
- # Additionally, we can add formatters via config in subclasses
920
+ # Additionally we can add formatters via config in subclasses
923
921
  config.formatters.add(
924
- iso8601: ->(value) { time.iso8601.round(6) },
922
+ iso8601: ->(value) { value.iso8601 },
925
923
  on_off: ->(value) { value ? 'ON' : 'OFF' },
926
924
  money: ->(value) { value.round(2) }
927
925
  )
928
926
 
929
927
  # Using predefined formatter
930
928
  attribute :commission, format: :money
931
- attribute :is_logined, format: :on_off
929
+ attribute :is_logged_in, format: :on_off
932
930
  attribute :created_at, format: :iso8601
933
931
  attribute :updated_at, format: :iso8601
934
932
 
935
933
  # Using `callable` formatter
936
- attribute :score_percent, format: PercentFormmatter # callable class
934
+ attribute :score_percent, format: PercentFormatter # callable class
937
935
  attribute :score_percent, format: proc { |percent| "#{percent.round(2)}%" }
938
936
  end
939
937
  ```
@@ -995,12 +993,11 @@ callables keep receiving the raw objects.
995
993
 
996
994
  ### Plugin :string_modifiers
997
995
 
998
- Allows to specify modifiers as strings.
999
-
1000
- Serialized attributes must be split with `,` and nested attributes must be
1001
- defined inside brackets `()`.
996
+ Allows `:only`, `:except` and `:with` to be given as a single comma-separated
997
+ string, with nested attributes in parentheses. Useful for accepting a field
998
+ list straight from a query parameter.
1002
999
 
1003
- Modifiers can still be provided the old way using nested hashes or arrays.
1000
+ Modifiers can still be provided the old way, as nested hashes or arrays.
1004
1001
 
1005
1002
  ```ruby
1006
1003
  PostSerializer.plugin :string_modifiers
@@ -1008,25 +1005,19 @@ PostSerializer.new(only: "id,user(id,username)").to_h(post)
1008
1005
  PostSerializer.new(except: "user(username,email)").to_h(post)
1009
1006
  PostSerializer.new(with: "user(email)").to_h(post)
1010
1007
 
1011
- # Modifiers can still be provided the old way using nested hashes or arrays.
1012
1008
  PostSerializer.new(with: {user: %i[email, username]}).to_h(post)
1013
1009
  ```
1014
1010
 
1015
1011
  ### Plugin :if
1016
1012
 
1017
- Plugin adds `:if, :unless, :if_value, :unless_value` options to
1018
- attributes so we can remove attributes from the response in various ways.
1019
-
1020
- Use `:if` and `:unless` when you want to hide attributes before finding
1021
- attribute value, and use `:if_value` and `:unless_value` to hide attributes
1022
- after getting the final value.
1023
-
1024
- Options `:if` and `:unless` accept currently serialized object and context as
1025
- parameters. Options `:if_value` and `:unless_value` accept already found
1026
- serialized value and context as parameters.
1013
+ Adds `:if`, `:unless`, `:if_value`, `:unless_value` attribute options to
1014
+ conditionally remove attributes from the response.
1027
1015
 
1028
- Options `:if_value` and `:unless_value` cannot be used with the `:serializer` option.
1029
- Use `:if` and `:unless` in this case.
1016
+ `:if`/`:unless` receive the serialized object and context, and are checked
1017
+ before the attribute value is found. `:if_value`/`:unless_value` receive the
1018
+ already-found value and context, checked after. The latter two cannot be
1019
+ used with the `:serializer` option, since a relationship has no "serialized
1020
+ value" of its own — use `:if`/`:unless` instead.
1030
1021
 
1031
1022
  See also a `:hide` option that is available without any plugins to hide
1032
1023
  attribute without conditions.
@@ -1058,24 +1049,18 @@ Look at [select serialized fields](#selecting-fields) for `:hide` usage examples
1058
1049
 
1059
1050
  ### Plugin :camel_case
1060
1051
 
1061
- By default, when we add an attribute like `attribute :first_name` it means:
1052
+ Without this plugin, responding with *camelCased* keys means specifying the
1053
+ attribute name and method directly for each attribute:
1054
+ `attribute :firstName, method: first_name`
1062
1055
 
1063
- - adding a `:first_name` key to the resulting hash
1064
- - adding a `#first_name` method call result as value
1056
+ This plugin camelCases every attribute name automatically, replacing `_x`
1057
+ with `X` throughout the string. The transformation runs once, when the
1058
+ attribute is defined, not on every serialization.
1065
1059
 
1066
- But it's often desired to respond with *camelCased* keys.
1067
- By default, this can be achieved by specifying the attribute name and method directly
1068
- for each attribute: `attribute :firstName, method: first_name`
1060
+ Provide a custom transformation when adding the plugin, for example
1061
+ `plugin :camel_case, transform: ->(name) { name.camelize }`
1069
1062
 
1070
- This plugin transforms all attribute names automatically.
1071
- We use a simple regular expression to replace `_x` with `X` for the whole string.
1072
- We make this transformation only once when the attribute is defined.
1073
-
1074
- You can provide custom transformation when adding the plugin,
1075
- for example `plugin :camel_case, transform: ->(name) { name.camelize }`
1076
-
1077
- For any attribute camelCase-behavior can be skipped when
1078
- the `camel_case: false` attribute option provided.
1063
+ Skip camelCase for a single attribute with `camel_case: false`.
1079
1064
 
1080
1065
  This plugin transforms only attribute keys, without affecting the `root`,
1081
1066
  `metadata` and `context_metadata` plugins keys.
@@ -1140,27 +1125,25 @@ end
1140
1125
 
1141
1126
  ### Plugin :explicit_many_option
1142
1127
 
1143
- The plugin requires adding a `:many` option when adding relationships
1144
- (attributes with the `:serializer` option or a block defining a nested
1145
- serializer).
1146
-
1147
- Adding this plugin makes it clearer to find if some relationship is an array or
1148
- a single object.
1128
+ Requires the `:many` option on every relationship attribute (an attribute
1129
+ with the `:serializer` option or a block defining a nested serializer), so
1130
+ it's always explicit whether it returns one object or many.
1149
1131
 
1150
1132
  ```ruby
1151
- class BaseSerializer < Serega
1152
- plugin :explicit_many_option
1153
- end
1133
+ class BaseSerializer < Serega
1134
+ plugin :explicit_many_option
1135
+ config.base_serializer = self
1136
+ end
1154
1137
 
1155
- class UserSerializer < BaseSerializer
1138
+ class PostSerializer < BaseSerializer
1139
+ attribute :text
1140
+
1141
+ attribute :user, many: false do
1156
1142
  attribute :name
1157
1143
  end
1158
1144
 
1159
- class PostSerializer < BaseSerializer
1160
- attribute :text
1161
- attribute :user, serializer: UserSerializer, many: false
1162
- attribute :comments, serializer: PostSerializer, many: true
1163
- end
1145
+ attribute :comments, serializer: PostSerializer, many: true
1146
+ end
1164
1147
  ```
1165
1148
 
1166
1149
  ## Errors
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.40.0
1
+ 0.40.1
@@ -4,10 +4,12 @@ class Serega
4
4
  #
5
5
  # Stores serialized attribute data
6
6
  #
7
+ # @private
7
8
  class SeregaAttribute
8
9
  #
9
10
  # Attribute instance methods
10
11
  #
12
+ # @private
11
13
  module AttributeInstanceMethods
12
14
  # Attribute initial params
13
15
  # @return [Hash] Attribute initial params
@@ -4,10 +4,12 @@ class Serega
4
4
  #
5
5
  # Prepares provided attribute options
6
6
  #
7
+ # @private
7
8
  class SeregaAttributeNormalizer
8
9
  #
9
10
  # AttributeNormalizer instance methods
10
11
  #
12
+ # @private
11
13
  module AttributeNormalizerInstanceMethods
12
14
  # Attribute initial params
13
15
  # @return [Hash] Attribute initial params
@@ -4,10 +4,12 @@ class Serega
4
4
  #
5
5
  # Attribute value resolvers
6
6
  #
7
+ # @private
7
8
  module AttributeValueResolvers
8
9
  #
9
10
  # Builds value resolver class for attributes with :batch option
10
11
  #
12
+ # @private
11
13
  class BatchResolver
12
14
  #
13
15
  # Generates callable block to find attribute value when attribute with :batch
@@ -55,6 +57,7 @@ class Serega
55
57
  #
56
58
  # Builds value resolver class for attributes with :batch option
57
59
  #
60
+ # @private
58
61
  class Batch
59
62
  def initialize(loader_name, id_method)
60
63
  @loader_name = loader_name
@@ -4,10 +4,12 @@ class Serega
4
4
  #
5
5
  # Attribute value resolvers
6
6
  #
7
+ # @private
7
8
  module AttributeValueResolvers
8
9
  #
9
10
  # Builds value resolver class for attributes with :const option
10
11
  #
12
+ # @private
11
13
  class ConstResolver
12
14
  #
13
15
  # Creates resolver that returns constant value
@@ -23,6 +25,7 @@ class Serega
23
25
  #
24
26
  # Value resolver class for attributes with :const option
25
27
  #
28
+ # @private
26
29
  class Const
27
30
  def initialize(const_value)
28
31
  @const_value = const_value
@@ -4,10 +4,12 @@ class Serega
4
4
  #
5
5
  # Attribute value resolvers
6
6
  #
7
+ # @private
7
8
  module AttributeValueResolvers
8
9
  #
9
10
  # Builds value resolver class for attributes with :delegate option
10
11
  #
12
+ # @private
11
13
  class DelegateResolver
12
14
  #
13
15
  # Creates resolver that delegates method call to another object
@@ -25,6 +27,7 @@ class Serega
25
27
  #
26
28
  # Value resolver class for attributes with :delegate (with :allow_nil) option
27
29
  #
30
+ # @private
28
31
  class DelegateAllowNil
29
32
  def initialize(delegate_to, method_name)
30
33
  @delegate_to = delegate_to
@@ -49,6 +52,7 @@ class Serega
49
52
  #
50
53
  # Value resolver class for attributes with :delegate (without :allow_nil) option
51
54
  #
55
+ # @private
52
56
  class Delegate
53
57
  def initialize(delegate_to, method_name)
54
58
  @delegate_to = delegate_to
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Serega
4
+ # @private
4
5
  module AttributeValueResolvers
5
6
  #
6
7
  # Builds value resolver for attributes with the :hash_access option
7
8
  #
9
+ # @private
8
10
  class HashAccessResolver
9
11
  # Allowed hash access modes
10
12
  MODES = %i[symbol string].freeze
@@ -27,6 +29,7 @@ class Serega
27
29
  # Builds value resolver for attributes with the :delegate option using
28
30
  # hash access on any of its steps
29
31
  #
32
+ # @private
30
33
  class HashAccessDelegateResolver
31
34
  #
32
35
  # Creates resolver that delegates through the provided step readers
@@ -45,6 +48,7 @@ class Serega
45
48
  #
46
49
  # Value resolver for attributes with the :hash_access option
47
50
  #
51
+ # @private
48
52
  class HashAccessKeyword
49
53
  def initialize(name, mode, allow_missing_key)
50
54
  @key = (mode == :symbol) ? name.to_sym : name.to_s
@@ -72,6 +76,7 @@ class Serega
72
76
  #
73
77
  # Value resolver for attributes with :hash_access and :delegate (without :allow_nil) options
74
78
  #
79
+ # @private
75
80
  class HashAccessDelegate
76
81
  def initialize(to_step, final_step)
77
82
  @to_step = to_step
@@ -92,6 +97,7 @@ class Serega
92
97
  #
93
98
  # Value resolver for attributes with :hash_access and :delegate (with :allow_nil) options
94
99
  #
100
+ # @private
95
101
  class HashAccessDelegateAllowNil
96
102
  def initialize(to_step, final_step)
97
103
  @to_step = to_step
@@ -4,10 +4,12 @@ class Serega
4
4
  #
5
5
  # Attribute value resolvers
6
6
  #
7
+ # @private
7
8
  module AttributeValueResolvers
8
9
  #
9
10
  # Builds value resolver class for attributes with :keyword option
10
11
  #
12
+ # @private
11
13
  class KeywordResolver
12
14
  #
13
15
  # Creates resolver that calls method on object
@@ -23,6 +25,7 @@ class Serega
23
25
  #
24
26
  # Value resolver class for attributes with :keyword option
25
27
  #
28
+ # @private
26
29
  class Keyword
27
30
  def initialize(keyword)
28
31
  @keyword = keyword
@@ -5,8 +5,10 @@ class Serega
5
5
  # Builds Data objects from serialized hashes.
6
6
  # Used by `#to_data` / `.to_data`.
7
7
  #
8
+ # @private
8
9
  class SeregaDataBuilder
9
10
  # SeregaDataBuilder class methods
11
+ # @private
10
12
  module SeregaDataBuilderClassMethods
11
13
  #
12
14
  # Converts serialized Hash/Array result into a tree of Ruby Data objects
@@ -4,6 +4,7 @@ class Serega
4
4
  #
5
5
  # Batch feature main module
6
6
  #
7
+ # @private
7
8
  module SeregaEngine
8
9
  #
9
10
  # One serialization level: all objects serialized under a single plan and the
@@ -12,6 +13,7 @@ class Serega
12
13
  # or preload runs once over the whole set. A deeper level (its own plan) loads
13
14
  # separately.
14
15
  #
16
+ # @private
15
17
  class Level
16
18
  # @param serializer [SeregaObjectSerializer] serializer that resolves this level
17
19
  def initialize(serializer)
@@ -4,6 +4,7 @@ class Serega
4
4
  #
5
5
  # Batch feature main module
6
6
  #
7
+ # @private
7
8
  module SeregaEngine
8
9
  #
9
10
  # Level-order queue of serialization levels for one serialization run.
@@ -15,6 +16,7 @@ class Serega
15
16
  # Processing level-by-level lets a named batch loader and preloads run once per
16
17
  # level over all of its objects.
17
18
  #
19
+ # @private
18
20
  class LevelQueue
19
21
  def initialize
20
22
  @levels = []
@@ -4,14 +4,17 @@ class Serega
4
4
  #
5
5
  # Batch feature main module
6
6
  #
7
+ # @private
7
8
  module SeregaEngine
8
9
  #
9
10
  # Batch loader
10
11
  #
12
+ # @private
11
13
  class Loader
12
14
  #
13
15
  # BatchLoader instance methods
14
16
  #
17
+ # @private
15
18
  module InstanceMethods
16
19
  # BatchLoader initial params
17
20
  # @return [Hash] BatchLoader initial params
@@ -4,10 +4,12 @@ class Serega
4
4
  #
5
5
  # Helpers
6
6
  #
7
+ # @private
7
8
  module SeregaHelpers
8
9
  #
9
10
  # Stores link to current serializer class
10
11
  #
12
+ # @private
11
13
  module SerializerClassHelper
12
14
  # Shows serializer class current class is namespaced under
13
15
  # @return [Class<Serega>] Serializer class that current class is namespaced under.
@@ -9,10 +9,12 @@ class Serega
9
9
  # which resolves every attribute for every object and enqueues child levels for
10
10
  # relations.
11
11
  #
12
+ # @private
12
13
  class SeregaObjectSerializer
13
14
  #
14
15
  # SeregaObjectSerializer instance methods
15
16
  #
17
+ # @private
16
18
  module InstanceMethods
17
19
  attr_reader :context, :plan, :many, :opts, :level_queue
18
20
 
data/lib/serega/plan.rb CHANGED
@@ -5,10 +5,12 @@ class Serega
5
5
  # Constructs plan - list of serialized attributes.
6
6
  # We will traverse this plan to construct serialized response.
7
7
  #
8
+ # @private
8
9
  class SeregaPlan
9
10
  #
10
11
  # SeregaPlan class methods
11
12
  #
13
+ # @private
12
14
  module ClassMethods
13
15
  #
14
16
  # Constructs plan of attributes that should be serialized.
@@ -68,6 +70,7 @@ class Serega
68
70
  #
69
71
  # SeregaPlan instance methods
70
72
  #
73
+ # @private
71
74
  module InstanceMethods
72
75
  # Parent plan point
73
76
  # @return [SeregaPlanPoint, nil]
@@ -4,10 +4,12 @@ class Serega
4
4
  #
5
5
  # Combines attribute and nested attributes
6
6
  #
7
+ # @private
7
8
  class SeregaPlanPoint
8
9
  #
9
10
  # SeregaPlanPoint instance methods
10
11
  #
12
+ # @private
11
13
  module InstanceMethods
12
14
  # Link to current plan this point belongs to
13
15
  # @return [SeregaAttribute] Current plan