Class: Dbwatcher::Storage::BaseStorage Abstract

Inherits:
Object
  • Object
show all
Includes:
Concerns::ErrorHandler, Concerns::Timestampable
Defined in:
lib/dbwatcher/storage/base_storage.rb

Overview

This class is abstract.

Subclass and implement specific storage logic

Base class for all storage implementations

Provides common functionality for storage classes including file management, error handling, validation, and timestamping. Follows the Ruby style guide patterns for class organization.

Examples:

class MyStorage < BaseStorage
  include Concerns::Validatable

  validates_presence_of :id, :name

  def save(data)
    validate_presence!(data)
    safe_write_json(file_path, data)
  end
end

Constant Summary collapse

DEFAULT_PERMISSIONS =

Configuration constants

0o755
JSON_FILE_EXTENSION =
".json"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Timestampable

#age, included, #initialize_timestamps, #recently_created?, #recently_updated?, #touch_updated_at

Methods included from Concerns::ErrorHandler

#safe_operation, #with_error_handling

Constructor Details

#initialize(storage_path = nil) ⇒ BaseStorage

Initializes the base storage with configured path and file manager

Sets up the storage path from configuration, creates a file manager instance, and initializes timestamps.

Parameters:

  • storage_path (String, nil) (defaults to: nil)

    custom storage path (optional)

Raises:



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dbwatcher/storage/base_storage.rb', line 51

def initialize(storage_path = nil)
  @storage_path = storage_path || Dbwatcher.configuration.storage_path

  # Ensure storage path is valid
  if @storage_path.nil? || @storage_path.to_s.strip.empty?
    raise StorageError, "Storage path cannot be nil or empty. Please configure a valid storage path."
  end

  @file_manager = FileManager.new(@storage_path)
  initialize_timestamps
  ensure_storage_directory
end

Instance Attribute Details

#file_managerFileManager (readonly)

Returns the file manager instance.

Returns:



42
43
44
# File 'lib/dbwatcher/storage/base_storage.rb', line 42

def file_manager
  @file_manager
end

#storage_pathString (readonly)

Returns the configured storage path.

Returns:

  • (String)

    the configured storage path



39
40
41
# File 'lib/dbwatcher/storage/base_storage.rb', line 39

def storage_path
  @storage_path
end