Module: Serega::SeregaAttributeNormalizer::AttributeNormalizerInstanceMethods
- Included in:
- Serega::SeregaAttributeNormalizer
- Defined in:
- lib/serega/attribute_normalizer.rb
Overview
AttributeNormalizer instance methods
Constant Summary collapse
- AUTO_BATCH_LOADER =
Identity loader that routes relation/preload attributes through the batch mechanism. Its result is never read — the attribute's value block still computes the value.
proc { |records| records.to_h { |record| [record, record] } }
Instance Attribute Summary collapse
-
#init_block ⇒ Hash
readonly
Attribute initial params.
-
#init_name ⇒ Hash
readonly
Attribute initial params.
-
#init_opts ⇒ Hash
readonly
Attribute initial params.
Instance Method Summary collapse
-
#batch_loaders ⇒ Array<Symbol>
Shows specified batch loaders names.
-
#default ⇒ Object
Shows the default attribute value.
-
#hide ⇒ Boolean?
Shows if attribute is specified to be hidden.
-
#initialize(initials) ⇒ SeregaAttributeNormalizer
Instantiates attribute options normalizer.
-
#many ⇒ Boolean?
Shows if attribute is specified to be a one-to-many relationship.
-
#method_name ⇒ Symbol
Symbolized initial attribute method name.
-
#name ⇒ Symbol
Symbolized initial attribute name.
-
#preloads ⇒ Hash?
Shows normalized preloads for current attribute.
-
#serializer ⇒ Serega, ...
Shows specified attribute serializer.
-
#value_block ⇒ #call
Combines all options to return single block that will be used to find attribute value during serialization.
-
#value_block_signature ⇒ String
Detects value block parameters signature.
Instance Attribute Details
#init_block ⇒ Hash (readonly)
Attribute initial params
18 19 20 |
# File 'lib/serega/attribute_normalizer.rb', line 18 def init_block @init_block end |
#init_name ⇒ Hash (readonly)
Attribute initial params
18 19 20 |
# File 'lib/serega/attribute_normalizer.rb', line 18 def init_name @init_name end |
#init_opts ⇒ Hash (readonly)
Attribute initial params
18 19 20 |
# File 'lib/serega/attribute_normalizer.rb', line 18 def init_opts @init_opts end |
Instance Method Details
#batch_loaders ⇒ Array<Symbol>
Shows specified batch loaders names
129 130 131 |
# File 'lib/serega/attribute_normalizer.rb', line 129 def batch_loaders @batch_loaders ||= prepare_batch_loaders end |
#default ⇒ Object
Shows the default attribute value. It is a value that replaces found nils.
When custom :default is not specified, we set empty array as default when many: true specified
109 110 111 112 113 |
# File 'lib/serega/attribute_normalizer.rb', line 109 def default return @default if instance_variable_defined?(:@default) @default = prepare_default end |
#hide ⇒ Boolean?
Shows if attribute is specified to be hidden
75 76 77 78 79 |
# File 'lib/serega/attribute_normalizer.rb', line 75 def hide return @hide if instance_variable_defined?(:@hide) @hide = prepare_hide end |
#initialize(initials) ⇒ SeregaAttributeNormalizer
Instantiates attribute options normalizer
27 28 29 30 31 |
# File 'lib/serega/attribute_normalizer.rb', line 27 def initialize(initials) @init_name = initials[:name] @init_opts = initials[:opts] @init_block = initials[:block] end |
#many ⇒ Boolean?
Shows if attribute is specified to be a one-to-many relationship
86 87 88 89 90 |
# File 'lib/serega/attribute_normalizer.rb', line 86 def many return @many if instance_variable_defined?(:@many) @many = prepare_many end |
#method_name ⇒ Symbol
Symbolized initial attribute method name
47 48 49 |
# File 'lib/serega/attribute_normalizer.rb', line 47 def method_name @method_name ||= prepare_method_name end |
#name ⇒ Symbol
Symbolized initial attribute name
38 39 40 |
# File 'lib/serega/attribute_normalizer.rb', line 38 def name @name ||= prepare_name end |
#preloads ⇒ Hash?
Shows normalized preloads for current attribute
120 121 122 123 124 |
# File 'lib/serega/attribute_normalizer.rb', line 120 def preloads return @preloads if instance_variable_defined?(:@preloads) @preloads = prepare_preloads end |
#serializer ⇒ Serega, ...
Shows specified attribute serializer
96 97 98 99 100 |
# File 'lib/serega/attribute_normalizer.rb', line 96 def serializer return @serializer if instance_variable_defined?(:@serializer) @serializer = prepare_serializer end |
#value_block ⇒ #call
Combines all options to return single block that will be used to find attribute value during serialization
57 58 59 |
# File 'lib/serega/attribute_normalizer.rb', line 57 def value_block @value_block ||= prepare_value_block end |
#value_block_signature ⇒ String
Detects value block parameters signature
66 67 68 |
# File 'lib/serega/attribute_normalizer.rb', line 66 def value_block_signature @value_block_signature ||= SeregaUtils::MethodSignature.call(value_block, pos_limit: 2, keyword_args: [:ctx]) end |