Class: MediaTypes::Serialization::SerializationAliasRegistration

Inherits:
SerializationBaseRegistration show all
Defined in:
lib/media_types/serialization/serialization_registration.rb

Overview

A registration that calls another registration when called.

Instance Attribute Summary collapse

Attributes inherited from SerializationBaseRegistration

#display_identifier, #inout, #serializer, #validator

Instance Method Summary collapse

Constructor Details

#initialize(serializer, inout, validator, display_identifier, target, optional, hide_variant) ⇒ SerializationAliasRegistration

Returns a new instance of SerializationAliasRegistration.



216
217
218
219
220
221
# File 'lib/media_types/serialization/serialization_registration.rb', line 216

def initialize(serializer, inout, validator, display_identifier, target, optional, hide_variant)
  self.target = target
  self.optional = optional
  self.hide_variant = hide_variant
  super(serializer, inout, validator, display_identifier)
end

Instance Attribute Details

#hide_variantObject

Returns the value of attribute hide_variant.



242
243
244
# File 'lib/media_types/serialization/serialization_registration.rb', line 242

def hide_variant
  @hide_variant
end

#optionalObject

Returns the value of attribute optional.



242
243
244
# File 'lib/media_types/serialization/serialization_registration.rb', line 242

def optional
  @optional
end

#targetObject

Returns the value of attribute target.



242
243
244
# File 'lib/media_types/serialization/serialization_registration.rb', line 242

def target
  @target
end

Instance Method Details

#call(victim, context, dsl: nil, raw: nil) ⇒ Object



238
239
240
# File 'lib/media_types/serialization/serialization_registration.rb', line 238

def call(victim, context, dsl: nil, raw: nil)
  target.call(victim, context, dsl: dsl, raw: raw)
end

#decode(victim, context) ⇒ Object



234
235
236
# File 'lib/media_types/serialization/serialization_registration.rb', line 234

def decode(victim, context)
  target.decode(victim, context)
end

#merge(other) ⇒ Object



223
224
225
226
227
228
229
230
231
232
# File 'lib/media_types/serialization/serialization_registration.rb', line 223

def merge(other)
  if optional
    return other unless other.is_a?(SerializationAliasRegistration)
  else
    return nil if other.is_a?(SerializationAliasRegistration) && !other.optional # two non-optional can't merge
    return self
  end

  other # if both optional, or other is !optional, newer one wins.
end