serega 0.50.0 → 0.51.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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/serega/attribute/serializer_reference.rb +27 -0
  4. data/lib/serega/attribute/value_code.rb +63 -0
  5. data/lib/serega/attribute.rb +80 -102
  6. data/lib/serega/attribute_normalizer.rb +43 -17
  7. data/lib/serega/attribute_normalizers/preloads.rb +5 -4
  8. data/lib/serega/attribute_value_resolvers/base.rb +35 -0
  9. data/lib/serega/attribute_value_resolvers/batch.rb +14 -1
  10. data/lib/serega/attribute_value_resolvers/callable.rb +52 -0
  11. data/lib/serega/attribute_value_resolvers/const.rb +11 -1
  12. data/lib/serega/attribute_value_resolvers/delegate.rb +12 -2
  13. data/lib/serega/attribute_value_resolvers/hash_access.rb +19 -4
  14. data/lib/serega/attribute_value_resolvers/keyword.rb +10 -3
  15. data/lib/serega/attribute_values.rb +4 -18
  16. data/lib/serega/conditions.rb +26 -1
  17. data/lib/serega/config.rb +45 -6
  18. data/lib/serega/engine/pulls.rb +3 -16
  19. data/lib/serega/engine/run.rb +4 -9
  20. data/lib/serega/errors.rb +26 -2
  21. data/lib/serega/formatters/callable.rb +44 -0
  22. data/lib/serega/formatters/method.rb +55 -0
  23. data/lib/serega/formatters.rb +27 -0
  24. data/lib/serega/plan/cache.rb +83 -60
  25. data/lib/serega/plan/depth_limit.rb +36 -0
  26. data/lib/serega/plan/per_ractor_cache.rb +11 -6
  27. data/lib/serega/plan/point.rb +67 -0
  28. data/lib/serega/plan/presets.rb +116 -0
  29. data/lib/serega/plan/selection.rb +94 -0
  30. data/lib/serega/plan/selection_planner.rb +50 -0
  31. data/lib/serega/plan.rb +41 -55
  32. data/lib/serega/plugins/metadata/meta_attribute.rb +17 -1
  33. data/lib/serega/plugins/metadata/metadata.rb +1 -10
  34. data/lib/serega/plugins/root/root.rb +11 -8
  35. data/lib/serega/presenter.rb +20 -0
  36. data/lib/serega/result_builder.rb +1 -1
  37. data/lib/serega/result_code/attribute_point_code.rb +117 -0
  38. data/lib/serega/result_code/point_code.rb +54 -0
  39. data/lib/serega/result_code/relation_point_code.rb +112 -0
  40. data/lib/serega/result_code.rb +41 -85
  41. data/lib/serega/source_group.rb +36 -67
  42. data/lib/serega/utils/camel_case.rb +22 -0
  43. data/lib/serega/utils/collection_detector.rb +3 -2
  44. data/lib/serega/utils/{parse_string_modifiers.rb → parse_string_selection.rb} +2 -2
  45. data/lib/serega/utils/ruby_literal.rb +28 -0
  46. data/lib/serega/validations/attribute/check_opt_preset.rb +34 -0
  47. data/lib/serega/validations/attribute/check_opt_selection.rb +41 -0
  48. data/lib/serega/validations/check_attribute_params.rb +4 -4
  49. data/lib/serega/validations/check_definition_selection.rb +21 -0
  50. data/lib/serega/validations/check_preset_params.rb +103 -0
  51. data/lib/serega/validations/check_relation_selection.rb +31 -0
  52. data/lib/serega/validations/check_selection.rb +89 -0
  53. data/lib/serega.rb +94 -30
  54. data/sig/serega.rbs +23 -7
  55. metadata +25 -5
  56. data/lib/serega/formatter.rb +0 -98
  57. data/lib/serega/plan_point.rb +0 -58
  58. data/lib/serega/validations/initiate/check_modifiers.rb +0 -87
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- #
5
- # Combines attribute and nested attributes
6
- #
7
- class SeregaPlanPoint # :nodoc:
8
- # Link to current plan this point belongs to
9
- attr_reader :plan
10
-
11
- # Shows current attribute
12
- attr_reader :attribute
13
-
14
- # Attribute `name`
15
- attr_reader :name
16
-
17
- # Shows child plan if exists
18
- attr_reader :child_plan
19
-
20
- # Whether the relation values of a class are collections, for a point
21
- # with a child plan
22
- attr_reader :collection_classes
23
-
24
- # Initializes plan point
25
- def initialize(plan, attribute, modifiers = nil)
26
- @plan = plan
27
- @attribute = attribute
28
- @name = attribute.name
29
- @child_plan = serializer ? SeregaPlan.new(serializer, self, modifiers || FROZEN_EMPTY_HASH) : nil
30
- @collection_classes = @child_plan ? {}.compare_by_identity : nil
31
- end
32
-
33
- # Attribute `many` option
34
- def many
35
- attribute.many
36
- end
37
-
38
- # Attribute `serializer` option
39
- def serializer
40
- attribute.serializer
41
- end
42
-
43
- # Attribute `batch_loaders`
44
- def batch_loaders
45
- attribute.batch_loaders
46
- end
47
-
48
- # Attribute `preloads`
49
- def preloads
50
- attribute.preloads
51
- end
52
-
53
- # Attribute `conditional?`
54
- def conditional?
55
- attribute.conditional?
56
- end
57
- end
58
- end
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Serega
4
- module SeregaValidations # :nodoc:
5
- #
6
- # Validations that take place when initializing serializer
7
- #
8
- module Initiate # :nodoc:
9
- #
10
- # Modifiers validation
11
- #
12
- class CheckModifiers # :nodoc:
13
- #
14
- # Instantiates modifiers validator
15
- #
16
- def initialize
17
- @parents_names = nil
18
- @error_attributes = nil
19
- end
20
-
21
- # Validates provided fields names are existing attributes
22
- def call(serializer_class, only, with, except)
23
- validate(serializer_class, only)
24
- validate(serializer_class, with)
25
- validate(serializer_class, except)
26
-
27
- raise_errors(serializer_class) if any_error?
28
- end
29
-
30
- private
31
-
32
- def validate(serializer_class, fields)
33
- fields.each do |name, nested_fields|
34
- attribute = serializer_class && serializer_class.attributes[name]
35
-
36
- # Save error when no attribute with checked name exists
37
- unless attribute
38
- save_error(name)
39
- next
40
- end
41
-
42
- # Return when attribute has no nested fields
43
- next if nested_fields.empty?
44
-
45
- with_parent_name(name) do
46
- validate(attribute.serializer, nested_fields)
47
- end
48
- end
49
- end
50
-
51
- def parents_names
52
- @parents_names ||= []
53
- end
54
-
55
- def with_parent_name(name)
56
- parents_names << name
57
- yield
58
- parents_names.pop
59
- end
60
-
61
- def error_attributes
62
- @error_attributes ||= []
63
- end
64
-
65
- def save_error(name)
66
- error_attributes << build_full_attribute_name(*parents_names, name)
67
- end
68
-
69
- def build_full_attribute_name(*names)
70
- head, *nested = *names
71
- result = +head.to_s # names are symbols, we need not frozen string
72
- nested.each { |nested_name| result << "(" << nested_name.to_s }
73
- nested.each { result << ")" }
74
- result
75
- end
76
-
77
- def raise_errors(serializer_class)
78
- raise Serega::AttributeNotExist.new("Not existing attributes: #{error_attributes.join(", ")}", serializer_class, error_attributes)
79
- end
80
-
81
- def any_error?
82
- !@error_attributes.nil?
83
- end
84
- end
85
- end
86
- end
87
- end