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: ad827e730d35f4e1805b7a0c59e8a8eeec87a91bb426ada370ea4a632516f40c
4
- data.tar.gz: 681deb3a954453740ac3256614684601aeb18027423352ca05cc62c82ff37784
3
+ metadata.gz: 7f1f7a73c9b59105be934686739f94fcdd90bad6b18101669336e57bd7303f98
4
+ data.tar.gz: 5506044c823665604fe6329774cbedc699d02c5ecaea7096750a5ee7c16bffcc
5
5
  SHA512:
6
- metadata.gz: 6f279fecc4038a162b33d97001fa993758eb4d687c0a7b83f9555f20781e3ece12b1381ba9765993cf5a4d7a31a5dee66f29d3279e1198a6ddf6b6d19b977682
7
- data.tar.gz: c1ed8f5f7e06ff2df08f2f5fb8ee587d062e3197399475c55d1383ab0fcb6c4c8f5224363ef202ecccdab063964a9e5cf98581ecdacfa5ac5caafa02277c93c6
6
+ metadata.gz: c21d5b4f1b5eaca35a65459e8e344daf711615bf27baae3fd9db85fb554ac227d487636257878b8a0df757c5b1ac8e63a0d640f8fda5fff402d88cf40e5ac1c8
7
+ data.tar.gz: c519aa2e0446495ed3791ea3bfdb356e34cfba4821648421b69371f77fd87e1c6704436457ca1fd2bc7b4d58d4db189d1eb9650e85511a4988f5a066c4e302a9
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
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
- @value_block = formatted_block(formatter, original_block)
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] = {auto_preload_relations: opts.fetch(:auto_preload_relations, true)}
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][:auto_preload_relations]
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::Error, "Attribute #{field_name} not exists"
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::Error, "Attribute #{field_name} is not a relation to add '#{first_nested}' attribute"
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
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-25 00:00:00.000000000 Z
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: