Module: Cuprum::Collections::Adaptable::Query

Defined in:
lib/cuprum/collections/adaptable/query.rb

Overview

Mixin for adaptable collection Query implementations.

Defined Under Namespace

Classes: AbstractQueryError, InvalidDataError

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#adapterCuprum::Collections::Adapter (readonly)

Returns the collection adapter.

Returns:

  • the collection adapter.



23
24
25
# File 'lib/cuprum/collections/adaptable/query.rb', line 23

def adapter
  @adapter
end

Instance Method Details

#convert(native) ⇒ Object

Converts a native data representation to the adapter entity format.

Parameters:

  • the native representation of one collection item.

Returns:

  • the collection item in the format specified by the adapter.

Raises:



31
32
33
34
35
36
37
38
39
40
# File 'lib/cuprum/collections/adaptable/query.rb', line 31

def convert(native)
  attributes = convert_native_to_attributes(native)
  result     = adapter.build(attributes:)

  return result.value if result.success?

  # This is an internal data error, not resolvable by the user.
  raise InvalidDataError,
    invalid_data_error_message(attributes:, error: result.error, native:)
end

#initialize(adapter:) ⇒ Object

Parameters:

  • the collection adapter.



16
17
18
19
20
# File 'lib/cuprum/collections/adaptable/query.rb', line 16

def initialize(*, adapter:, **)
  super(*, **)

  @adapter = adapter
end