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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/serega/attribute/serializer_reference.rb +27 -0
- data/lib/serega/attribute/value_code.rb +63 -0
- data/lib/serega/attribute.rb +80 -102
- data/lib/serega/attribute_normalizer.rb +43 -17
- data/lib/serega/attribute_normalizers/preloads.rb +5 -4
- data/lib/serega/attribute_value_resolvers/base.rb +35 -0
- data/lib/serega/attribute_value_resolvers/batch.rb +14 -1
- data/lib/serega/attribute_value_resolvers/callable.rb +52 -0
- data/lib/serega/attribute_value_resolvers/const.rb +11 -1
- data/lib/serega/attribute_value_resolvers/delegate.rb +12 -2
- data/lib/serega/attribute_value_resolvers/hash_access.rb +19 -4
- data/lib/serega/attribute_value_resolvers/keyword.rb +10 -3
- data/lib/serega/attribute_values.rb +4 -18
- data/lib/serega/conditions.rb +26 -1
- data/lib/serega/config.rb +45 -6
- data/lib/serega/engine/pulls.rb +3 -16
- data/lib/serega/engine/run.rb +4 -9
- data/lib/serega/errors.rb +26 -2
- data/lib/serega/formatters/callable.rb +44 -0
- data/lib/serega/formatters/method.rb +55 -0
- data/lib/serega/formatters.rb +27 -0
- data/lib/serega/plan/cache.rb +83 -60
- data/lib/serega/plan/depth_limit.rb +36 -0
- data/lib/serega/plan/per_ractor_cache.rb +11 -6
- data/lib/serega/plan/point.rb +67 -0
- data/lib/serega/plan/presets.rb +116 -0
- data/lib/serega/plan/selection.rb +94 -0
- data/lib/serega/plan/selection_planner.rb +50 -0
- data/lib/serega/plan.rb +41 -55
- data/lib/serega/plugins/metadata/meta_attribute.rb +17 -1
- data/lib/serega/plugins/metadata/metadata.rb +1 -10
- data/lib/serega/plugins/root/root.rb +11 -8
- data/lib/serega/presenter.rb +20 -0
- data/lib/serega/result_builder.rb +1 -1
- data/lib/serega/result_code/attribute_point_code.rb +117 -0
- data/lib/serega/result_code/point_code.rb +54 -0
- data/lib/serega/result_code/relation_point_code.rb +112 -0
- data/lib/serega/result_code.rb +41 -85
- data/lib/serega/source_group.rb +36 -67
- data/lib/serega/utils/camel_case.rb +22 -0
- data/lib/serega/utils/collection_detector.rb +3 -2
- data/lib/serega/utils/{parse_string_modifiers.rb → parse_string_selection.rb} +2 -2
- data/lib/serega/utils/ruby_literal.rb +28 -0
- data/lib/serega/validations/attribute/check_opt_preset.rb +34 -0
- data/lib/serega/validations/attribute/check_opt_selection.rb +41 -0
- data/lib/serega/validations/check_attribute_params.rb +4 -4
- data/lib/serega/validations/check_definition_selection.rb +21 -0
- data/lib/serega/validations/check_preset_params.rb +103 -0
- data/lib/serega/validations/check_relation_selection.rb +31 -0
- data/lib/serega/validations/check_selection.rb +89 -0
- data/lib/serega.rb +94 -30
- data/sig/serega.rbs +23 -7
- metadata +25 -5
- data/lib/serega/formatter.rb +0 -98
- data/lib/serega/plan_point.rb +0 -58
- data/lib/serega/validations/initiate/check_modifiers.rb +0 -87
data/lib/serega/plan_point.rb
DELETED
|
@@ -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
|