Class: JSONAPI::Realizer::Adapter

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/jsonapi/realizer/adapter.rb,
lib/jsonapi/realizer/adapter/active_record.rb

Defined Under Namespace

Modules: ActiveRecord

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interface:) ⇒ Adapter

Returns a new instance of Adapter.

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jsonapi/realizer/adapter.rb', line 19

def initialize(interface:)
  super(interface:)

  validate!

  mappings = MAPPINGS.merge(JSONAPI::Realizer.configuration.adapter_mappings).with_indifferent_access

  raise(ArgumentError, "you've given an invalid adapter alias: #{interface}, we support #{mappings.keys.to_sentence}") unless mappings.key?(interface)

  singleton_class.prepend(mappings.fetch(interface))

  raise(ArgumentError, "need to provide a Adapter#find_one interface") unless respond_to?(:find_one)
  raise(ArgumentError, "need to provide a Adapter#find_many interface") unless respond_to?(:find_many)
  raise(ArgumentError, "need to provide a Adapter#write_attributes interface") unless respond_to?(:write_attributes)
  raise(ArgumentError, "need to provide a Adapter#write_relationships interface") unless respond_to?(:write_relationships)
  raise(ArgumentError, "need to provide a Adapter#include_relationships interface") unless respond_to?(:include_relationships)
  raise(ArgumentError, "need to provide a Adapter#paginate interface") unless respond_to?(:paginate)
  raise(ArgumentError, "need to provide a Adapter#sorting interface") unless respond_to?(:sorting)
  raise(ArgumentError, "need to provide a Adapter#filtering interface") unless respond_to?(:filtering)
end

Instance Attribute Details

#interfaceObject

Returns the value of attribute interface.



15
16
17
# File 'lib/jsonapi/realizer/adapter.rb', line 15

def interface
  @interface
end