Class: Cuprum::Collections::Adapters::HashAdapter

Inherits:
Cuprum::Collections::Adapter show all
Defined in:
lib/cuprum/collections/adapters/hash_adapter.rb

Overview

Utility class for converting between raw attributes and a data Hash.

Instance Attribute Summary

Attributes inherited from Cuprum::Collections::Adapter

#attribute_names, #default_contract, #entity_class

Instance Method Summary collapse

Methods inherited from Cuprum::Collections::Adapter

#allow_extra_attributes?, #build, #merge, #serialize, #validate, #validate_attributes_parameter, #validate_entity_parameter

Constructor Details

#initialize(**options) ⇒ HashAdapter

Returns a new instance of HashAdapter.

Parameters:

  • options (Hash)

    options for initializing the adapter.

Options Hash (**options):

  • allow_extra_attributes (true, false)

    if false, attributes methods return an error for attributes not in attributes_names. Defaults to true if attribute_names is empty, otherwise false.

  • attributes_names (Array<String, Symbol>)

    the valid attribute names for a data object. Defaults to [].

  • default_contract (Stannum::Constraints:Base)

    the contract used to validate instances of the data object.



18
19
20
21
22
23
24
# File 'lib/cuprum/collections/adapters/hash_adapter.rb', line 18

def initialize(**options)
  if options[:entity_class]
    raise ArgumentError, 'adapter does not support entity class'
  end

  super(entity_class: Hash, **options)
end