Class: DIDWW::ComplexObject::AuthenticationMethod::Generic

Inherits:
Base
  • Object
show all
Defined in:
lib/didww/complex_objects/authentication_methods/generic.rb

Overview

Fallback class used when the server returns an authentication_method of a type this gem version does not know about yet. Preserves the unrecognized type and attributes so callers can introspect and round-trip them back to the server without data loss.

When a new authentication method type ships server-side, the gem should be updated to add a dedicated subclass; Generic exists so forward deployments don’t silently downgrade to raw Hashes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, #as_json_api, #attributes, cast, property, schema, type

Constructor Details

#initialize(params = {}, stored_type = nil) ⇒ Generic

Returns a new instance of Generic.



17
18
19
20
21
22
# File 'lib/didww/complex_objects/authentication_methods/generic.rb', line 17

def initialize(params = {}, stored_type = nil)
  @stored_type = stored_type
  # Keep unknown attributes in the attributes hash, since we have no
  # property DSL declarations to validate against.
  params.each { |k, v| attributes[k] = v }
end

Instance Attribute Details

#stored_typeObject (readonly)

Returns the value of attribute stored_type.



15
16
17
# File 'lib/didww/complex_objects/authentication_methods/generic.rb', line 15

def stored_type
  @stored_type
end

Instance Method Details

#as_jsonObject



28
29
30
# File 'lib/didww/complex_objects/authentication_methods/generic.rb', line 28

def as_json(*)
  { type: type, attributes: attributes.as_json }.with_indifferent_access
end

#typeObject



24
25
26
# File 'lib/didww/complex_objects/authentication_methods/generic.rb', line 24

def type
  stored_type || self.class.type
end