serega 0.21.0 → 0.30.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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +113 -229
  3. data/VERSION +1 -1
  4. data/lib/serega/attribute.rb +31 -3
  5. data/lib/serega/attribute_normalizer.rb +143 -42
  6. data/lib/serega/batch/attribute_loader.rb +70 -0
  7. data/lib/serega/batch/attribute_loaders.rb +59 -0
  8. data/lib/serega/batch/auto_resolver.rb +24 -0
  9. data/lib/serega/batch/auto_resolver_factory.rb +48 -0
  10. data/lib/serega/batch/loader.rb +67 -0
  11. data/lib/serega/config.rb +59 -1
  12. data/lib/serega/object_serializer.rb +11 -9
  13. data/lib/serega/plan.rb +16 -0
  14. data/lib/serega/plan_point.rb +31 -5
  15. data/lib/serega/plugins/activerecord_preloads/activerecord_preloads.rb +25 -13
  16. data/lib/serega/plugins/activerecord_preloads/lib/active_record_objects.rb +31 -0
  17. data/lib/serega/plugins/camel_case/camel_case.rb +1 -1
  18. data/lib/serega/plugins/formatters/formatters.rb +79 -22
  19. data/lib/serega/plugins/if/if.rb +41 -22
  20. data/lib/serega/plugins/if/validations/check_opt_if.rb +27 -6
  21. data/lib/serega/plugins/if/validations/check_opt_if_value.rb +27 -6
  22. data/lib/serega/plugins/if/validations/check_opt_unless.rb +27 -6
  23. data/lib/serega/plugins/if/validations/check_opt_unless_value.rb +27 -6
  24. data/lib/serega/plugins/metadata/meta_attribute.rb +9 -10
  25. data/lib/serega/plugins/metadata/validations/check_block.rb +2 -4
  26. data/lib/serega/plugins/metadata/validations/check_opt_value.rb +2 -3
  27. data/lib/serega/plugins/presenter/presenter.rb +1 -1
  28. data/lib/serega/utils/format_user_preloads.rb +58 -0
  29. data/lib/serega/utils/method_signature.rb +89 -0
  30. data/lib/serega/utils/preload_paths.rb +53 -0
  31. data/lib/serega/utils/preloads_constructor.rb +77 -0
  32. data/lib/serega/validations/attribute/check_block.rb +38 -6
  33. data/lib/serega/validations/attribute/check_opt_batch.rb +101 -0
  34. data/lib/serega/validations/attribute/check_opt_const.rb +1 -0
  35. data/lib/serega/validations/attribute/check_opt_delegate.rb +1 -0
  36. data/lib/serega/validations/attribute/check_opt_method.rb +1 -0
  37. data/lib/serega/{plugins/preloads/validations → validations/attribute}/check_opt_preload.rb +2 -2
  38. data/lib/serega/{plugins/preloads/validations → validations/attribute}/check_opt_preload_path.rb +3 -3
  39. data/lib/serega/validations/attribute/check_opt_value.rb +35 -9
  40. data/lib/serega/validations/check_attribute_params.rb +3 -2
  41. data/lib/serega/validations/check_batch_loader_params.rb +80 -0
  42. data/lib/serega/validations/initiate/check_modifiers.rb +1 -1
  43. data/lib/serega.rb +98 -7
  44. metadata +17 -37
  45. data/lib/serega/plugins/batch/batch.rb +0 -168
  46. data/lib/serega/plugins/batch/lib/batch_config.rb +0 -77
  47. data/lib/serega/plugins/batch/lib/loader.rb +0 -113
  48. data/lib/serega/plugins/batch/lib/loaders.rb +0 -45
  49. data/lib/serega/plugins/batch/lib/modules/attribute.rb +0 -26
  50. data/lib/serega/plugins/batch/lib/modules/attribute_normalizer.rb +0 -78
  51. data/lib/serega/plugins/batch/lib/modules/check_attribute_params.rb +0 -22
  52. data/lib/serega/plugins/batch/lib/modules/config.rb +0 -23
  53. data/lib/serega/plugins/batch/lib/modules/object_serializer.rb +0 -46
  54. data/lib/serega/plugins/batch/lib/modules/plan_point.rb +0 -22
  55. data/lib/serega/plugins/batch/lib/plugins_extensions/activerecord_preloads.rb +0 -43
  56. data/lib/serega/plugins/batch/lib/plugins_extensions/formatters.rb +0 -54
  57. data/lib/serega/plugins/batch/lib/plugins_extensions/if.rb +0 -31
  58. data/lib/serega/plugins/batch/lib/plugins_extensions/preloads.rb +0 -34
  59. data/lib/serega/plugins/batch/lib/validations/check_batch_opt_id_method.rb +0 -43
  60. data/lib/serega/plugins/batch/lib/validations/check_batch_opt_loader.rb +0 -59
  61. data/lib/serega/plugins/batch/lib/validations/check_opt_batch.rb +0 -62
  62. data/lib/serega/plugins/preloads/lib/format_user_preloads.rb +0 -60
  63. data/lib/serega/plugins/preloads/lib/modules/attribute.rb +0 -28
  64. data/lib/serega/plugins/preloads/lib/modules/attribute_normalizer.rb +0 -99
  65. data/lib/serega/plugins/preloads/lib/modules/check_attribute_params.rb +0 -22
  66. data/lib/serega/plugins/preloads/lib/modules/config.rb +0 -19
  67. data/lib/serega/plugins/preloads/lib/modules/plan_point.rb +0 -41
  68. data/lib/serega/plugins/preloads/lib/preload_paths.rb +0 -53
  69. data/lib/serega/plugins/preloads/lib/preloads_config.rb +0 -62
  70. data/lib/serega/plugins/preloads/lib/preloads_constructor.rb +0 -79
  71. data/lib/serega/plugins/preloads/preloads.rb +0 -162
  72. data/lib/serega/utils/params_count.rb +0 -50
  73. data/lib/serega/validations/utils/check_extra_keyword_arg.rb +0 -33
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- # Lists batch loaders registered during serialization
7
- class SeregaBatchLoaders
8
- # BatchLoaders instance methods
9
- module InstanceMethods
10
- #
11
- # Initializes or fetches already initialized batch loader
12
- #
13
- # @param plan_point [Serega::SeregaPlanPoint] current plan point
14
- # @param object_serializer[Serega::SeregaObjectSerializer] current object serializer
15
- #
16
- # @return [Serega::SeregaPlugins::Batch::SeregaBatchLoader] Batch Loader
17
- #
18
- def get(plan_point, object_serializer)
19
- batch_loaders[plan_point] ||= self.class.serializer_class::SeregaBatchLoader.new(object_serializer, plan_point)
20
- end
21
-
22
- #
23
- # Loads all registered batches and removes them from registered list
24
- #
25
- def load_all
26
- return unless defined?(@batch_loaders)
27
-
28
- while (_point, batch_loader = batch_loaders.shift)
29
- batch_loader.load
30
- end
31
- end
32
-
33
- private
34
-
35
- def batch_loaders
36
- @batch_loaders ||= {}.compare_by_identity
37
- end
38
- end
39
-
40
- include InstanceMethods
41
- extend Serega::SeregaHelpers::SerializerClassHelper
42
- end
43
- end
44
- end
45
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- #
7
- # Serega::SeregaAttribute additional/patched class methods
8
- #
9
- # @see Serega::SeregaAttribute
10
- #
11
- module AttributeInstanceMethods
12
- #
13
- # @return [nil, Hash] :batch option
14
- #
15
- attr_reader :batch
16
-
17
- private
18
-
19
- def set_normalized_vars(normalizer)
20
- super
21
- @batch = normalizer.batch
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- #
7
- # SeregaAttributeNormalizer additional/patched instance methods
8
- #
9
- # @see SeregaAttributeNormalizer::AttributeInstanceMethods
10
- #
11
- module AttributeNormalizerInstanceMethods
12
- #
13
- # Returns normalized attribute :batch option with prepared :key and
14
- # :default options. Option :loader will be prepared at serialization
15
- # time as loaders are usually defined after attributes.
16
- #
17
- # @return [Hash] attribute :batch normalized options
18
- #
19
- def batch
20
- return @batch if instance_variable_defined?(:@batch)
21
-
22
- @batch = prepare_batch
23
- end
24
-
25
- private
26
-
27
- #
28
- # Patch for original `prepare_hide` method
29
- #
30
- # Marks attribute hidden if auto_hide option was set and attribute has batch loader
31
- #
32
- def prepare_hide
33
- res = super
34
- return res unless res.nil?
35
-
36
- if batch
37
- self.class.serializer_class.config.batch.auto_hide || nil
38
- end
39
- end
40
-
41
- def prepare_batch
42
- batch = init_opts[:batch]
43
- return unless batch
44
-
45
- loader = prepare_batch_loader(batch[:loader])
46
-
47
- id_method = batch[:id_method] || self.class.serializer_class.config.batch.id_method
48
- id_method = prepare_batch_id_method(id_method)
49
-
50
- {loader: loader, id_method: id_method, default: default}
51
- end
52
-
53
- def prepare_batch_id_method(id_method)
54
- return proc { |object| object.public_send(id_method) } if id_method.is_a?(Symbol)
55
-
56
- params_count = SeregaUtils::ParamsCount.call(id_method, max_count: 2)
57
- case params_count
58
- when 0 then proc { id_method.call }
59
- when 1 then proc { |object| id_method.call(object) }
60
- else id_method
61
- end
62
- end
63
-
64
- def prepare_batch_loader(loader)
65
- loader = self.class.serializer_class.config.batch.loaders.fetch(loader) if loader.is_a?(Symbol)
66
-
67
- params_count = SeregaUtils::ParamsCount.call(loader, max_count: 3)
68
- case params_count
69
- when 0 then proc { loader.call }
70
- when 1 then proc { |object| loader.call(object) }
71
- when 2 then proc { |object, context| loader.call(object, context) }
72
- else loader
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- #
7
- # Serega::SeregaValidations::CheckAttributeParams additional/patched class methods
8
- #
9
- # @see Serega::SeregaValidations::CheckAttributeParams
10
- #
11
- module CheckAttributeParamsInstanceMethods
12
- private
13
-
14
- def check_opts
15
- super
16
-
17
- CheckOptBatch.call(opts, block, self.class.serializer_class)
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- #
7
- # Config class additional/patched instance methods
8
- #
9
- # @see Serega::SeregaConfig
10
- #
11
- module ConfigInstanceMethods
12
- #
13
- # Returns all batch loaders registered for current serializer
14
- #
15
- # @return [Serega::SeregaPlugins::Batch::BatchConfig] configuration for batch loaded attributes
16
- #
17
- def batch
18
- @batch ||= BatchConfig.new(opts.fetch(:batch))
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- #
7
- # SeregaObjectSerializer additional/patched class methods
8
- #
9
- # @see Serega::SeregaObjectSerializer
10
- #
11
- module SeregaObjectSerializerInstanceMethods
12
- private
13
-
14
- def attach_value(object, point, container)
15
- batch = point.batch
16
- return super unless batch
17
-
18
- remember_key_for_batch_loading(batch, object, point, container)
19
- end
20
-
21
- def remember_key_for_batch_loading(batch, object, point, container)
22
- id = batch[:id_method].call(object, context)
23
- batch_loader(point).remember(id, container)
24
- container[point.name] = nil # Reserve attribute place in resulted hash. We will set correct value later
25
- end
26
-
27
- def batch_loader(point)
28
- batch_loaders = opts[:batch_loaders]
29
- raise_batch_plugin_for_serializer_not_defined(point) unless batch_loaders
30
- batch_loaders.get(point, self)
31
- end
32
-
33
- def raise_batch_plugin_for_serializer_not_defined(point)
34
- root_plan = point.plan
35
- root_plan = plan.parent_plan_point.plan while root_plan.parent_plan_point
36
- current_serializer = root_plan.serializer_class
37
- nested_serializer = self.class.serializer_class
38
-
39
- raise SeregaError,
40
- "Plugin :batch must be added to current serializer (#{current_serializer})" \
41
- " to load attributes with :batch option in nested serializer (#{nested_serializer})"
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- #
7
- # Serega::SeregaPlanPoint additional/patched class methods
8
- #
9
- # @see SeregaAttribute
10
- #
11
- module PlanPointInstanceMethods
12
- #
13
- # Returns attribute :batch option with prepared loader
14
- # @return [Hash] attribute :batch option
15
- #
16
- def batch
17
- attribute.batch
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- #
7
- # Extensions (mini-plugins) that are enabled when :batch plugin used with other plugins
8
- #
9
- module PluginsExtensions
10
- #
11
- # Extension that is used when :batch plugin used with :active_record_preloads plugin
12
- #
13
- module ActiveRecordPreloads
14
- #
15
- # BatchLoader additional/patched instance methods
16
- #
17
- # @see Serega::SeregaPlugins::Batch::SeregaBatchLoader
18
- #
19
- module BatchLoaderInstanceMethods
20
- private
21
-
22
- # Preloads required associations to batch-loaded records
23
- def keys_values
24
- data = super
25
-
26
- if point.child_plan
27
- associations = point.preloads
28
- return data if associations.empty?
29
-
30
- records = data.values
31
- records.flatten!(1)
32
-
33
- ActiverecordPreloads::Preloader.preload(records, associations)
34
- end
35
-
36
- data
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- #
7
- # Extensions (mini-plugins) that are enabled when :batch plugin used with other plugins
8
- #
9
- module PluginsExtensions
10
- #
11
- # Extension that is used when batch plugin used with :formatters plugin
12
- #
13
- module Formatters
14
- #
15
- # BatchLoader additional/patched instance methods
16
- #
17
- # @see Serega::SeregaPlugins::Batch::SeregaBatchLoader
18
- #
19
- module BatchLoaderInstanceMethods
20
- private
21
-
22
- # Format values after they are prepared
23
- def keys_values
24
- data = super
25
-
26
- formatter = point.attribute.formatter
27
- data.transform_values! { |value| formatter.call(value) } if formatter
28
-
29
- data
30
- end
31
- end
32
-
33
- #
34
- # SeregaAttribute additional/patched instance methods
35
- #
36
- # @see Serega::SeregaAttribute
37
- #
38
- module SeregaAttributeInstanceMethods
39
- # Normalized formatter block or callable instance
40
- # @return [#call, nil] Normalized formatter block or callable instance
41
- attr_reader :formatter
42
-
43
- private
44
-
45
- def set_normalized_vars(normalizer)
46
- super
47
- @formatter = normalizer.formatter
48
- end
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- #
7
- # Extensions (mini-plugins) that are enabled when :batch plugin used with other plugins
8
- #
9
- module PluginsExtensions
10
- #
11
- # Extension that is used when :if plugin is loaded
12
- #
13
- module If
14
- #
15
- # SeregaObjectSerializer additional/patched class methods
16
- #
17
- # @see Serega::SeregaObjectSerializer
18
- #
19
- module ObjectSerializerInstanceMethods123
20
- private
21
-
22
- # Removes key added by `batch` plugin at the start of serialization to preserve attributes ordering
23
- def attach_final_value(value, point, container)
24
- container.delete(point.name) if super == SeregaPlugins::If::KEY_SKIPPED
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- #
7
- # Extensions (mini-plugins) that are enabled when :batch plugin used with other plugins
8
- #
9
- module PluginsExtensions
10
- #
11
- # Extension that is used when :preloads plugin is loaded
12
- #
13
- module Preloads
14
- #
15
- # Attribute additional/patched instance methods
16
- #
17
- # @see Serega::SeregaPlugins::Preloads::AttributeNormalizerInstanceMethods
18
- #
19
- module AttributeNormalizerInstanceMethods
20
- private
21
-
22
- # Do not add any preloads automatically when batch option provided
23
- def prepare_preloads
24
- opts = init_opts
25
- return if opts.key?(:batch) && !opts.key?(:preload)
26
-
27
- super
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- #
7
- # Validator for option :id_method in attribute :batch option
8
- #
9
- class CheckBatchOptIdMethod
10
- class << self
11
- #
12
- # Checks option :id_method of attribute :batch option
13
- #
14
- # @param id [nil, #call] Attribute :batch option :id_method
15
- #
16
- # @raise [SeregaError] validation error
17
- #
18
- # @return [void]
19
- #
20
- def call(id)
21
- return if id.is_a?(Symbol)
22
-
23
- raise SeregaError, must_be_callable unless id.respond_to?(:call)
24
-
25
- SeregaValidations::Utils::CheckExtraKeywordArg.call(id, "batch option :id_method")
26
- params_count = SeregaUtils::ParamsCount.call(id, max_count: 2)
27
- raise SeregaError, params_count_error if params_count > 2
28
- end
29
-
30
- private
31
-
32
- def params_count_error
33
- "Invalid :batch option :id_method. It can accept maximum 2 parameters (object, context)"
34
- end
35
-
36
- def must_be_callable
37
- "Invalid :batch option :id_method. It must be a Symbol, a Proc or respond to #call"
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- #
7
- # Validator for option :loader in attribute :batch option
8
- #
9
- class CheckBatchOptLoader
10
- class << self
11
- #
12
- # Checks option :loader of attribute :batch option
13
- #
14
- # @param loader [nil, #call] Attribute :batch option :loader
15
- #
16
- # @raise [SeregaError] validation error
17
- #
18
- # @return [void]
19
- #
20
- def call(loader, serializer_class)
21
- if loader.is_a?(Symbol)
22
- check_symbol(loader, serializer_class)
23
- else
24
- check_callable(loader)
25
- end
26
- end
27
-
28
- private
29
-
30
- def check_symbol(loader_name, serializer_class)
31
- defined_loaders = serializer_class.config.batch.loaders
32
- return if defined_loaders[loader_name]
33
-
34
- raise SeregaError, <<~ERR.strip
35
- Please define loader before adding it to attribute.
36
- Example: `config.batch.define(:#{loader_name}) { |ids| ... }`
37
- ERR
38
- end
39
-
40
- def check_callable(loader)
41
- raise SeregaError, must_be_callable unless loader.respond_to?(:call)
42
-
43
- SeregaValidations::Utils::CheckExtraKeywordArg.call(loader, ":batch option :loader")
44
- params_count = SeregaUtils::ParamsCount.call(loader, max_count: 3)
45
- raise SeregaError, params_count_error if params_count > 3
46
- end
47
-
48
- def params_count_error
49
- "Invalid :batch option :loader. It can accept maximum 3 parameters (ids, context, plan)"
50
- end
51
-
52
- def must_be_callable
53
- "Invalid :batch option :loader. It must be a Symbol, a Proc or respond to :call"
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Batch
6
- #
7
- # Attribute `:batch` option validator
8
- #
9
- class CheckOptBatch
10
- class << self
11
- #
12
- # Checks attribute :batch option
13
- #
14
- # @param opts [Hash] Attribute options
15
- #
16
- # @raise [SeregaError] Attribute validation error
17
- #
18
- # @return [void]
19
- #
20
- def call(opts, block, serializer_class)
21
- return unless opts.key?(:batch)
22
-
23
- SeregaValidations::Utils::CheckOptIsHash.call(opts, :batch)
24
-
25
- batch = opts[:batch]
26
- SeregaValidations::Utils::CheckAllowedKeys.call(batch, %i[id_method loader], :batch)
27
-
28
- check_batch_opt_id_method(batch, serializer_class)
29
- check_batch_opt_loader(batch, serializer_class)
30
- check_usage_with_other_params(opts, block)
31
- end
32
-
33
- private
34
-
35
- def check_batch_opt_id_method(batch, serializer_class)
36
- return if !batch.key?(:id_method) && serializer_class.config.batch.id_method
37
-
38
- id_method = batch[:id_method]
39
- raise SeregaError, "Option :id_method must present inside :batch option" unless id_method
40
-
41
- CheckBatchOptIdMethod.call(id_method)
42
- end
43
-
44
- def check_batch_opt_loader(batch, serializer_class)
45
- loader = batch[:loader]
46
- raise SeregaError, "Option :loader must present inside :batch option" unless loader
47
-
48
- CheckBatchOptLoader.call(loader, serializer_class)
49
- end
50
-
51
- def check_usage_with_other_params(opts, block)
52
- raise SeregaError, "Option :batch can not be used together with option :method" if opts.key?(:method)
53
- raise SeregaError, "Option :batch can not be used together with option :value" if opts.key?(:value)
54
- raise SeregaError, "Option :batch can not be used together with option :const" if opts.key?(:const)
55
- raise SeregaError, "Option :batch can not be used together with option :delegate" if opts.key?(:delegate)
56
- raise SeregaError, "Option :batch can not be used together with block" if block
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Preloads
6
- #
7
- # Utility that helps to transform user provided preloads to hash
8
- #
9
- class FormatUserPreloads
10
- class << self
11
- #
12
- # Transforms user provided preloads to hash
13
- #
14
- # @param value [Array,Hash,String,Symbol,nil,false] preloads
15
- #
16
- # @return [Hash] preloads transformed to hash
17
- #
18
- def call(value)
19
- case value
20
- when Array then array_to_hash(value)
21
- when FalseClass then nil_to_hash(value)
22
- when Hash then hash_to_hash(value)
23
- when NilClass then nil_to_hash(value)
24
- when String then string_to_hash(value)
25
- when Symbol then symbol_to_hash(value)
26
- else raise Serega::SeregaError,
27
- "Preload option value can consist from Symbols, Arrays, Hashes (#{value.class} #{value.inspect} was provided)"
28
- end
29
- end
30
-
31
- private
32
-
33
- def array_to_hash(values)
34
- values.each_with_object({}) do |value, obj|
35
- obj.merge!(call(value))
36
- end
37
- end
38
-
39
- def hash_to_hash(values)
40
- values.each_with_object({}) do |(key, value), obj|
41
- obj[key.to_sym] = call(value)
42
- end
43
- end
44
-
45
- def nil_to_hash(_value)
46
- {}
47
- end
48
-
49
- def string_to_hash(value)
50
- {value.to_sym => {}}
51
- end
52
-
53
- def symbol_to_hash(value)
54
- {value => {}}
55
- end
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaPlugins
5
- module Preloads
6
- #
7
- # Serega::SeregaAttribute additional/patched instance methods
8
- #
9
- # @see Serega::SeregaAttribute::AttributeInstanceMethods
10
- #
11
- module AttributeInstanceMethods
12
- # @return [Hash, nil] normalized preloads of current attribute
13
- attr_reader :preloads
14
-
15
- # @return [Array] normalized preloads_path of current attribute
16
- attr_reader :preloads_path
17
-
18
- private
19
-
20
- def set_normalized_vars(normalizer)
21
- super
22
- @preloads = normalizer.preloads
23
- @preloads_path = normalizer.preloads_path
24
- end
25
- end
26
- end
27
- end
28
- end