serega 0.8.3 → 0.10.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/README.md +60 -10
- data/VERSION +1 -1
- data/lib/serega/attribute.rb +9 -1
- data/lib/serega/config.rb +16 -0
- data/lib/serega/object_serializer.rb +13 -1
- data/lib/serega/plugins/batch/batch.rb +8 -7
- data/lib/serega/plugins/batch/lib/loader.rb +3 -0
- data/lib/serega/plugins/if/if.rb +168 -0
- data/lib/serega/plugins/if/validations/check_opt_if.rb +79 -0
- data/lib/serega/plugins/if/validations/check_opt_if_value.rb +84 -0
- data/lib/serega/plugins/if/validations/check_opt_unless.rb +88 -0
- data/lib/serega/plugins/if/validations/check_opt_unless_value.rb +84 -0
- data/lib/serega/plugins/metadata/meta_attribute.rb +10 -2
- data/lib/serega/plugins/metadata/metadata.rb +15 -13
- data/lib/serega/plugins/metadata/validations/check_path.rb +10 -17
- data/lib/serega/plugins/preloads/preloads.rb +2 -0
- data/lib/serega/plugins/presenter/presenter.rb +10 -8
- data/lib/serega/plugins/string_modifiers/parse_string_modifiers.rb +46 -57
- data/lib/serega/plugins/string_modifiers/string_modifiers.rb +3 -7
- data/lib/serega/utils/enum_deep_dup.rb +2 -2
- data/lib/serega/validations/attribute/check_name.rb +8 -21
- data/lib/serega/validations/check_attribute_params.rb +10 -1
- data/lib/serega.rb +72 -48
- metadata +8 -4
- data/lib/serega/plugins/hide_nil/hide_nil.rb +0 -106
@@ -1,106 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Serega
|
4
|
-
module SeregaPlugins
|
5
|
-
#
|
6
|
-
# Plugin adds `:hide_nil` option to attributes to delete them from final result
|
7
|
-
# if value is nil
|
8
|
-
#
|
9
|
-
module HideNil
|
10
|
-
# @return [Symbol] Plugin name
|
11
|
-
def self.plugin_name
|
12
|
-
:hide_nil
|
13
|
-
end
|
14
|
-
|
15
|
-
#
|
16
|
-
# Applies plugin code to specific serializer
|
17
|
-
#
|
18
|
-
# @param serializer_class [Class<Serega>] Current serializer class
|
19
|
-
# @param _opts [Hash] Loaded plugins options
|
20
|
-
#
|
21
|
-
# @return [void]
|
22
|
-
#
|
23
|
-
def self.load_plugin(serializer_class, **_opts)
|
24
|
-
serializer_class::SeregaAttribute.include(AttributeInstanceMethods)
|
25
|
-
serializer_class::CheckAttributeParams.include(CheckAttributeParamsInstanceMethods)
|
26
|
-
serializer_class::SeregaObjectSerializer.include(SeregaObjectSerializerInstanceMethods)
|
27
|
-
end
|
28
|
-
|
29
|
-
#
|
30
|
-
# Adds config options and runs other callbacks after plugin was loaded
|
31
|
-
#
|
32
|
-
# @param serializer_class [Class<Serega>] Current serializer class
|
33
|
-
# @param opts [Hash] loaded plugins opts
|
34
|
-
#
|
35
|
-
# @return [void]
|
36
|
-
#
|
37
|
-
def self.after_load_plugin(serializer_class, **opts)
|
38
|
-
serializer_class.config.attribute_keys << :hide_nil
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Serega::SeregaAttribute additional/patched instance methods
|
43
|
-
#
|
44
|
-
# @see Serega::SeregaValidations::CheckAttributeParams
|
45
|
-
#
|
46
|
-
module AttributeInstanceMethods
|
47
|
-
# Check hide_nil is specified
|
48
|
-
def hide_nil?
|
49
|
-
!!opts[:hide_nil]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
#
|
54
|
-
# Serega::SeregaValidations::CheckAttributeParams additional/patched class methods
|
55
|
-
#
|
56
|
-
# @see Serega::SeregaValidations::CheckAttributeParams
|
57
|
-
#
|
58
|
-
module CheckAttributeParamsInstanceMethods
|
59
|
-
private
|
60
|
-
|
61
|
-
def check_opts
|
62
|
-
super
|
63
|
-
CheckOptHideNil.call(opts)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
#
|
68
|
-
# Validator class for :hide_nil attribute option
|
69
|
-
#
|
70
|
-
class CheckOptHideNil
|
71
|
-
#
|
72
|
-
# Checks attribute :hide_nil option
|
73
|
-
#
|
74
|
-
# @param opts [Hash] Attribute options
|
75
|
-
#
|
76
|
-
# @raise [Serega::SeregaError] SeregaError that option has invalid value
|
77
|
-
#
|
78
|
-
# @return [void]
|
79
|
-
#
|
80
|
-
def self.call(opts)
|
81
|
-
return unless opts.key?(:hide_nil)
|
82
|
-
|
83
|
-
value = opts[:hide_nil]
|
84
|
-
return if (value == true) || (value == false)
|
85
|
-
|
86
|
-
raise SeregaError, "Invalid option :hide_nil => #{value.inspect}. Must have a boolean value"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
#
|
91
|
-
# SeregaObjectSerializer additional/patched class methods
|
92
|
-
#
|
93
|
-
# @see Serega::SeregaObjectSerializer
|
94
|
-
#
|
95
|
-
module SeregaObjectSerializerInstanceMethods
|
96
|
-
private
|
97
|
-
|
98
|
-
def attach_final_value(final_value, *)
|
99
|
-
super unless final_value.nil?
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
register_plugin(HideNil.plugin_name, HideNil)
|
105
|
-
end
|
106
|
-
end
|