Class: Dbwatcher::Storage::Api::BaseAPI Abstract
- Inherits:
-
Object
- Object
- Dbwatcher::Storage::Api::BaseAPI
- Includes:
- Concerns::DataNormalizer
- Defined in:
- lib/dbwatcher/storage/api/base_api.rb
Overview
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.
Direct Known Subclasses
Instance Method Summary collapse
-
#all ⇒ Array
abstract
Get all results after applying filters.
-
#create(data) ⇒ Hash
abstract
Create a new record.
-
#initialize(storage) ⇒ BaseAPI
constructor
Initialize the API with a storage backend.
-
#limit(count) ⇒ BaseAPI
Apply limit to results.
-
#where(conditions) ⇒ BaseAPI
Filter by conditions.
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
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
#all ⇒ Array
Subclasses should implement this method
Get all results after applying filters
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
Subclasses should implement this method if creation is supported
Create a new 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
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
46 47 48 49 |
# File 'lib/dbwatcher/storage/api/base_api.rb', line 46 def where(conditions) @filters.merge!(conditions) self end |