serega 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f1f7a73c9b59105be934686739f94fcdd90bad6b18101669336e57bd7303f98
|
4
|
+
data.tar.gz: 5506044c823665604fe6329774cbedc699d02c5ecaea7096750a5ee7c16bffcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c21d5b4f1b5eaca35a65459e8e344daf711615bf27baae3fd9db85fb554ac227d487636257878b8a0df757c5b1ac8e63a0d640f8fda5fff402d88cf40e5ac1c8
|
7
|
+
data.tar.gz: c519aa2e0446495ed3791ea3bfdb356e34cfba4821648421b69371f77fd87e1c6704436457ca1fd2bc7b4d58d4db189d1eb9650e85511a4988f5a066c4e302a9
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
@@ -25,7 +25,15 @@ class Serega
|
|
25
25
|
formatter = opts[:format]
|
26
26
|
return original_block unless formatter
|
27
27
|
|
28
|
-
|
28
|
+
new_value_block = formatted_block(formatter, original_block)
|
29
|
+
|
30
|
+
# Detect formatted :const value in advance
|
31
|
+
if opts.key?(:const)
|
32
|
+
const_value = new_value_block.call
|
33
|
+
new_value_block = proc { const_value }
|
34
|
+
end
|
35
|
+
|
36
|
+
@value_block = new_value_block
|
29
37
|
end
|
30
38
|
|
31
39
|
private
|
@@ -35,7 +35,10 @@ class Serega
|
|
35
35
|
def self.after_load_plugin(serializer_class, **opts)
|
36
36
|
config = serializer_class.config
|
37
37
|
config[:attribute_keys] += [:preload, :preload_path]
|
38
|
-
config[:preloads] = {
|
38
|
+
config[:preloads] = {
|
39
|
+
auto_preload_attributes_with_serializer: opts.fetch(:auto_preload_attributes_with_serializer, false),
|
40
|
+
auto_hide_attributes_with_preload: opts.fetch(:auto_hide_attributes_with_preload, false)
|
41
|
+
}
|
39
42
|
end
|
40
43
|
|
41
44
|
# Adds #preloads instance method
|
@@ -60,14 +63,28 @@ class Serega
|
|
60
63
|
@preloads_path = get_preloads_path
|
61
64
|
end
|
62
65
|
|
66
|
+
def hide
|
67
|
+
res = super
|
68
|
+
return res unless res.nil?
|
69
|
+
|
70
|
+
auto_hide_attribute_with_preloads? || nil
|
71
|
+
end
|
72
|
+
|
63
73
|
private
|
64
74
|
|
75
|
+
def auto_hide_attribute_with_preloads?
|
76
|
+
return @auto_hide_attribute_with_preloads if defined?(@auto_hide_attribute_with_preloads)
|
77
|
+
|
78
|
+
auto = self.class.serializer_class.config[:preloads][:auto_hide_attributes_with_preload]
|
79
|
+
@auto_hide_attribute_with_preloads = auto && !preloads.nil? && (preloads != false) && (preloads != {})
|
80
|
+
end
|
81
|
+
|
65
82
|
def get_preloads
|
66
83
|
preloads_provided = opts.key?(:preload)
|
67
84
|
preloads =
|
68
85
|
if preloads_provided
|
69
86
|
opts[:preload]
|
70
|
-
elsif relation? && self.class.serializer_class.config[:preloads][:
|
87
|
+
elsif relation? && self.class.serializer_class.config[:preloads][:auto_preload_attributes_with_serializer]
|
71
88
|
key
|
72
89
|
end
|
73
90
|
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Serega
|
4
|
+
class AttributeNotExist < Error
|
5
|
+
end
|
6
|
+
|
4
7
|
module Plugins
|
5
8
|
module ValidateModifiers
|
6
9
|
class Validate
|
@@ -29,14 +32,14 @@ class Serega
|
|
29
32
|
def raise_error(name, prev_names)
|
30
33
|
field_name = field_name(name, prev_names)
|
31
34
|
|
32
|
-
raise Serega::
|
35
|
+
raise Serega::AttributeNotExist, "Attribute #{field_name} not exists"
|
33
36
|
end
|
34
37
|
|
35
38
|
def raise_nested_error(name, prev_names, nested_fields)
|
36
39
|
field_name = field_name(name, prev_names)
|
37
40
|
first_nested = nested_fields.keys.first
|
38
41
|
|
39
|
-
raise Serega::
|
42
|
+
raise Serega::AttributeNotExist, "Attribute #{field_name} has no :serializer option specified to add nested '#{first_nested}' attribute"
|
40
43
|
end
|
41
44
|
|
42
45
|
def field_name(name, prev_names)
|
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.1.
|
4
|
+
version: 0.1.5
|
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-07-
|
11
|
+
date: 2022-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|