Class: Dbwatcher::Storage::Api::BaseAPI Abstract

Inherits:
Object
  • Object
show all
Includes:
Concerns::DataNormalizer
Defined in:
lib/dbwatcher/storage/api/base_api.rb

Overview

This class is abstract.

Subclass and implement specific API methods

Base class for all storage API classes

This class provides common functionality and patterns for all storage API implementations (SessionAPI, QueryAPI, TableAPI). It establishes the foundation for the fluent interface pattern and shared filtering capabilities.

Examples:

class MyAPI < BaseAPI
  def my_filter(value)
    @filters[:my_key] = value
    self
  end
end

Direct Known Subclasses

QueryAPI, SessionAPI, TableAPI

Instance Method Summary collapse

Methods included from Concerns::DataNormalizer

#extract_value, #normalize_change, #normalize_hash_keys, #normalize_operation, #normalize_record_id, #normalize_session_data, #normalize_table_name, #normalize_timestamp

Constructor Details

#initialize(storage) ⇒ BaseAPI

Initialize the API with a storage backend

Parameters:

  • storage (Object)

    storage backend instance



27
28
29
30
31
# File 'lib/dbwatcher/storage/api/base_api.rb', line 27

def initialize(storage)
  @storage = storage
  @filters = {}
  @limit_value = nil
end

Instance Method Details

#allArray

This method is abstract.

Subclasses should implement this method

Get all results after applying filters

Returns:

  • (Array)

    filtered results

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/dbwatcher/storage/api/base_api.rb', line 55

def all
  raise NotImplementedError, "Subclasses must implement #all"
end

#create(data) ⇒ Hash

This method is abstract.

Subclasses should implement this method if creation is supported

Create a new record

Parameters:

  • data (Hash)

    record data

Returns:

  • (Hash)

    created record



64
65
66
# File 'lib/dbwatcher/storage/api/base_api.rb', line 64

def create(data)
  @storage.save(data)
end

#limit(count) ⇒ BaseAPI

Apply limit to results

Parameters:

  • count (Integer)

    maximum number of results

Returns:

  • (BaseAPI)

    self for method chaining



37
38
39
40
# File 'lib/dbwatcher/storage/api/base_api.rb', line 37

def limit(count)
  @limit_value = count
  self
end

#where(conditions) ⇒ BaseAPI

Filter by conditions

Parameters:

  • conditions (Hash)

    filtering conditions

Returns:

  • (BaseAPI)

    self for method chaining



46
47
48
49
# File 'lib/dbwatcher/storage/api/base_api.rb', line 46

def where(conditions)
  @filters.merge!(conditions)
  self
end