Class: Nl::DataTypes::NestTypeValue

Inherits:
Base
  • Object
show all
Defined in:
nl/lib/nl/datatypes.rb

Overview

Nested attributes whose type numbers are keys rather than members of an attribute set. Each level is returned as an Integer-keyed Hash; values at the innermost level are decoded as @attribute_set.

Instance Method Summary collapse

Methods inherited from Base

#nlattr_type_flags

Constructor Details

#initialize(attribute_set, levels, selector_bindings: []) ⇒ NestTypeValue

Returns a new instance of NestTypeValue.

Raises:

  • (ArgumentError)


340
341
342
343
344
345
346
# File 'nl/lib/nl/datatypes.rb', line 340

def initialize(attribute_set, levels, selector_bindings: [])
  raise ArgumentError, 'levels must be positive' unless levels.positive?

  @attribute_set = attribute_set
  @levels = levels
  @selector_bindings = selector_bindings
end

Instance Method Details

#coerce(value = nil, context: nil, **keywords) ⇒ Object



352
353
354
355
# File 'nl/lib/nl/datatypes.rb', line 352

def coerce(value = nil, context: nil, **keywords)
  value = keywords unless keywords.empty?
  coerce_level(value, @levels, selectors(context))
end

#decode(decoder, context: nil, nlattr_type_flags: 0) ⇒ Object



357
358
359
# File 'nl/lib/nl/datatypes.rb', line 357

def decode(decoder, context: nil, nlattr_type_flags: 0)
  decode_level(decoder, @levels, selectors(context))
end

#encode(encoder, value, context: nil) ⇒ Object



348
349
350
# File 'nl/lib/nl/datatypes.rb', line 348

def encode(encoder, value, context: nil)
  encode_level(encoder, value, @levels, selectors(context))
end