Class: Kabk::Adapters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/kabk/adapters/base.rb

Overview

Abstract base class for ORM Adapters

Direct Known Subclasses

SequelAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Base

Returns a new instance of Base.



9
10
11
# File 'lib/kabk/adapters/base.rb', line 9

def initialize(resource)
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



7
8
9
# File 'lib/kabk/adapters/base.rb', line 7

def resource
  @resource
end

Instance Method Details

#create(attributes, context: {}) ⇒ Object

Parameters:

  • attributes (Hash)

    Sanitized attributes

  • context (Hash) (defaults to: {})

    Context provided by host framework (e.g. current_user).

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/kabk/adapters/base.rb', line 27

def create(attributes, context: {})
  raise NotImplementedError, "#{self.class} must implement #create"
end

#delete(id, context: {}) ⇒ Object

Parameters:

  • id (Integer, String)

    Primary key

  • context (Hash) (defaults to: {})

    Context provided by host framework (e.g. current_user).

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/kabk/adapters/base.rb', line 40

def delete(id, context: {})
  raise NotImplementedError, "#{self.class} must implement #delete"
end

#get(id, context: {}) ⇒ Object

Parameters:

  • id (Integer, String)

    Primary key

  • context (Hash) (defaults to: {})

    Context provided by host framework (e.g. current_user).

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/kabk/adapters/base.rb', line 21

def get(id, context: {})
  raise NotImplementedError, "#{self.class} must implement #get"
end

#list(params, context: {}) ⇒ Object

Parameters:

  • params (Hash)

    Request parameters (page, per_page, sort, filters).

  • context (Hash) (defaults to: {})

    Context provided by host framework (e.g. current_user).

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/kabk/adapters/base.rb', line 15

def list(params, context: {})
  raise NotImplementedError, "#{self.class} must implement #list"
end

#update(id, attributes, context: {}) ⇒ Object

Parameters:

  • id (Integer, String)

    Primary key

  • attributes (Hash)

    Sanitized attributes

  • context (Hash) (defaults to: {})

    Context provided by host framework (e.g. current_user).

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/kabk/adapters/base.rb', line 34

def update(id, attributes, context: {})
  raise NotImplementedError, "#{self.class} must implement #update"
end