Class: Nl::DataTypes::NestedAttributes

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

Instance Method Summary collapse

Constructor Details

#initialize(attribute_set, selector_bindings: []) ⇒ NestedAttributes

Returns a new instance of NestedAttributes.



242
243
244
245
# File 'nl/lib/nl/datatypes.rb', line 242

def initialize(attribute_set, selector_bindings: [])
  @attribute_set = attribute_set
  @selector_bindings = selector_bindings
end

Instance Method Details

#coerce(value, context: nil) ⇒ Object



251
252
253
# File 'nl/lib/nl/datatypes.rb', line 251

def coerce(value, context: nil)
  value.is_a?(Hash) ? @attribute_set.build_attributes(value, external_selectors: selectors(context)) : value
end

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



263
264
265
# File 'nl/lib/nl/datatypes.rb', line 263

def decode(decoder, context: nil, nlattr_type_flags: 0)
  @attribute_set.decode(decoder, external_selectors: selectors(context))
end

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



255
256
257
258
259
260
261
# File 'nl/lib/nl/datatypes.rb', line 255

def encode(encoder, value, context: nil)
  unless value.is_a?(@attribute_set)
    raise TypeError, "value must be an instance of #{@attribute_set}"
  end

  value.encode(encoder, external_selectors: selectors(context))
end

#nlattr_type_flags(_value = nil, context: nil) ⇒ Object



247
248
249
# File 'nl/lib/nl/datatypes.rb', line 247

def nlattr_type_flags(_value = nil, context: nil)
  Raw::NLA_F_NESTED
end