serega 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/serega/plugins/formatters/formatters.rb +2 -1
- data/lib/serega/plugins/lazy/lazy.rb +53 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1aec10f062296a0af1d3f6b445f189ab2d84a145a8ed3cf0d52c81aa0c4f2c69
|
4
|
+
data.tar.gz: 1038ea10d7ea09b25d8f74b0561319d6f518a447121686ed689ff16385ec8806
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d568f45860671e760f56f67fd8206b2476b97ee5d415e881f23c9226285ef5b99a87b12ebd5da552664b6cd345ccb90cf7d43e10ed2a563ef436159f81afec5
|
7
|
+
data.tar.gz: 3100f9a6bd3b8fba77175677d4e53c01abf467cf2c57a5c1eea6a71ac2fbd73e7d2c0b0ff7071a032acdd73e6b37af37cc3259421e4fc58a96d5400fdea215ed
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
@@ -12,9 +12,10 @@ class Serega
|
|
12
12
|
serializer_class::SeregaAttribute.include(AttributeInstanceMethods)
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.after_load_plugin(serializer_class, **
|
15
|
+
def self.after_load_plugin(serializer_class, **opts)
|
16
16
|
config = serializer_class.config
|
17
17
|
config.opts[:formatters] = {}
|
18
|
+
config.formatters.add(opts[:formatters] || {})
|
18
19
|
config.attribute_keys << :format
|
19
20
|
end
|
20
21
|
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Serega
|
4
|
+
module SeregaPlugins
|
5
|
+
module Lazy
|
6
|
+
def self.plugin_name
|
7
|
+
:lazy
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.before_load_plugin(serializer_class, **opts)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.load_plugin(serializer_class, **_opts)
|
14
|
+
serializer_class.extend(ClassMethods)
|
15
|
+
serializer_class.include(InstanceMethods)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.after_load_plugin(serializer_class, **_opts)
|
19
|
+
serializer_class.config.attribute_keys << :lazy
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
def lazy(key:, buffer:, resolver:)
|
25
|
+
@lazy[key] = { buffer: buffer, resolver: resolver }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module InstanceMethods
|
30
|
+
def initialize(*args, **kwargs)
|
31
|
+
super
|
32
|
+
@lazy = {}
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_h(*args, **kwargs)
|
36
|
+
result = super
|
37
|
+
lazy.each_key do |key, |
|
38
|
+
buffer = lazy.delete(key) # { val => [paths], val2 => [paths2] }
|
39
|
+
buffer_values = self.class.lazy[key][:resolver].(buffer.keys)
|
40
|
+
|
41
|
+
buffer_values.each do |key, resolved_value|
|
42
|
+
paths = buffer[key]
|
43
|
+
paths.each do |path|
|
44
|
+
result.dig(path[0, -2])
|
45
|
+
replace(result, buffer_values)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
register_plugin(Metadata.plugin_name, Metadata)
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serega
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Glushkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- lib/serega/plugins/context_metadata/context_metadata.rb
|
36
36
|
- lib/serega/plugins/formatters/formatters.rb
|
37
37
|
- lib/serega/plugins/hide_nil/hide_nil.rb
|
38
|
+
- lib/serega/plugins/lazy/lazy.rb
|
38
39
|
- lib/serega/plugins/metadata/meta_attribute.rb
|
39
40
|
- lib/serega/plugins/metadata/metadata.rb
|
40
41
|
- lib/serega/plugins/metadata/validations/check_block.rb
|