Module: Serega::SeregaAttributeNormalizer::AttributeNormalizerInstanceMethods

Included in:
Serega::SeregaAttributeNormalizer
Defined in:
lib/serega/attribute_normalizer.rb

Overview

AttributeNormalizer instance methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#init_blockHash (readonly)

Attribute initial params

Returns:

  • (Hash)

    Attribute initial params



14
15
16
# File 'lib/serega/attribute_normalizer.rb', line 14

def init_block
  @init_block
end

#init_nameHash (readonly)

Attribute initial params

Returns:

  • (Hash)

    Attribute initial params



14
15
16
# File 'lib/serega/attribute_normalizer.rb', line 14

def init_name
  @init_name
end

#init_optsHash (readonly)

Attribute initial params

Returns:

  • (Hash)

    Attribute initial params



14
15
16
# File 'lib/serega/attribute_normalizer.rb', line 14

def init_opts
  @init_opts
end

Instance Method Details

#batch_loadersArray<Symbol>

Shows specified batch loaders names

Returns:

  • (Array<Symbol>)

    specified serializer



136
137
138
# File 'lib/serega/attribute_normalizer.rb', line 136

def batch_loaders
  @batch_loaders ||= prepare_batch_loaders
end

#defaultObject

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

Returns:

  • (Object)

    Attribute default value



105
106
107
108
109
# File 'lib/serega/attribute_normalizer.rb', line 105

def default
  return @default if instance_variable_defined?(:@default)

  @default = prepare_default
end

#hideBoolean?

Shows if attribute is specified to be hidden

Returns:

  • (Boolean, nil)

    if attribute must be hidden by default



71
72
73
74
75
# File 'lib/serega/attribute_normalizer.rb', line 71

def hide
  return @hide if instance_variable_defined?(:@hide)

  @hide = prepare_hide
end

#initialize(initials) ⇒ SeregaAttributeNormalizer

Instantiates attribute options normalizer

Parameters:

  • initials (Hash)

    new attribute options

Returns:



23
24
25
26
27
# File 'lib/serega/attribute_normalizer.rb', line 23

def initialize(initials)
  @init_name = initials[:name]
  @init_opts = initials[:opts]
  @init_block = initials[:block]
end

#manyBoolean?

Shows if attribute is specified to be a one-to-many relationship

Returns:

  • (Boolean, nil)

    if attribute is specified to be a one-to-many relationship



82
83
84
85
86
# File 'lib/serega/attribute_normalizer.rb', line 82

def many
  return @many if instance_variable_defined?(:@many)

  @many = prepare_many
end

#method_nameSymbol

Symbolized initial attribute method name

Returns:

  • (Symbol)

    Attribute normalized method name



43
44
45
# File 'lib/serega/attribute_normalizer.rb', line 43

def method_name
  @method_name ||= prepare_method_name
end

#nameSymbol

Symbolized initial attribute name

Returns:

  • (Symbol)

    Attribute normalized name



34
35
36
# File 'lib/serega/attribute_normalizer.rb', line 34

def name
  @name ||= prepare_name
end

#preloadsHash?

Shows normalized preloads for current attribute

Returns:

  • (Hash, nil)

    normalized preloads of current attribute



116
117
118
119
120
# File 'lib/serega/attribute_normalizer.rb', line 116

def preloads
  return @preloads if instance_variable_defined?(:@preloads)

  @preloads = prepare_preloads
end

#preloads_pathArray

Shows normalized preloads_path for current attribute

Returns:

  • (Array)

    normalized preloads_path of current attribute



127
128
129
130
131
# File 'lib/serega/attribute_normalizer.rb', line 127

def preloads_path
  return @preloads_path if instance_variable_defined?(:@preloads_path)

  @preloads_path = prepare_preloads_path
end

#serializerSerega, ...

Shows specified attribute serializer

Returns:

  • (Serega, String, #callable, nil)

    specified serializer



92
93
94
95
96
# File 'lib/serega/attribute_normalizer.rb', line 92

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

Returns:

  • (#call)

    Attribute normalized callable value block



53
54
55
# File 'lib/serega/attribute_normalizer.rb', line 53

def value_block
  @value_block ||= prepare_value_block
end

#value_block_signatureString

Detects value block parameters signature

Returns:

  • (String)

    value block parameters signature



62
63
64
# File 'lib/serega/attribute_normalizer.rb', line 62

def value_block_signature
  @value_block_signature ||= SeregaUtils::MethodSignature.call(value_block, pos_limit: 2, keyword_args: [:ctx])
end