Class: Tabscanner::Config
- Inherits:
-
Object
- Object
- Tabscanner::Config
- Defined in:
- lib/tabscanner/config.rb
Overview
Configuration class implementing singleton pattern
This class manages global configuration for the Tabscanner gem. It implements the singleton pattern to ensure consistent configuration across the entire application.
Instance Attribute Summary collapse
-
#api_key ⇒ String?
The API key for Tabscanner service.
-
#base_url ⇒ String?
Override base URL for API calls.
-
#debug ⇒ Boolean
Enable debug logging and enhanced error details (default: false).
-
#logger ⇒ Logger
Get or create the logger instance.
-
#region ⇒ String
The region for API calls (default: ‘us’).
Class Method Summary collapse
-
.instance ⇒ Config
Thread-safe singleton instance access.
-
.reset! ⇒ Object
private
Reset the singleton instance (primarily for testing).
Instance Method Summary collapse
-
#debug? ⇒ Boolean
Check if debug mode is enabled.
-
#initialize ⇒ Config
constructor
Initialize configuration with default values from environment variables.
-
#validate! ⇒ Object
Validate that required configuration is present.
Constructor Details
#initialize ⇒ Config
Initialize configuration with default values from environment variables
41 42 43 44 45 46 47 |
# File 'lib/tabscanner/config.rb', line 41 def initialize @api_key = ENV['TABSCANNER_API_KEY'] @region = ENV['TABSCANNER_REGION'] || 'us' @base_url = ENV['TABSCANNER_BASE_URL'] @debug = ENV['TABSCANNER_DEBUG'] == 'true' || false @logger = nil # Will be created lazily in logger method end |
Instance Attribute Details
#api_key ⇒ String?
Returns The API key for Tabscanner service.
38 39 40 |
# File 'lib/tabscanner/config.rb', line 38 def api_key @api_key end |
#base_url ⇒ String?
Returns Override base URL for API calls.
38 |
# File 'lib/tabscanner/config.rb', line 38 attr_accessor :api_key, :region, :base_url, :debug, :logger |
#debug ⇒ Boolean
Returns Enable debug logging and enhanced error details (default: false).
38 |
# File 'lib/tabscanner/config.rb', line 38 attr_accessor :api_key, :region, :base_url, :debug, :logger |
#logger ⇒ Logger
Get or create the logger instance
38 |
# File 'lib/tabscanner/config.rb', line 38 attr_accessor :api_key, :region, :base_url, :debug, :logger |
#region ⇒ String
Returns The region for API calls (default: ‘us’).
38 |
# File 'lib/tabscanner/config.rb', line 38 attr_accessor :api_key, :region, :base_url, :debug, :logger |
Class Method Details
.instance ⇒ Config
Thread-safe singleton instance access
51 52 53 |
# File 'lib/tabscanner/config.rb', line 51 def self.instance @instance ||= new end |
.reset! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reset the singleton instance (primarily for testing)
57 58 59 |
# File 'lib/tabscanner/config.rb', line 57 def self.reset! @instance = nil end |
Instance Method Details
#debug? ⇒ Boolean
Check if debug mode is enabled
74 75 76 |
# File 'lib/tabscanner/config.rb', line 74 def debug? !!@debug end |
#validate! ⇒ Object
Validate that required configuration is present
80 81 82 83 |
# File 'lib/tabscanner/config.rb', line 80 def validate! raise Tabscanner::ConfigurationError, "API key is required" if api_key.nil? || api_key.empty? raise Tabscanner::ConfigurationError, "Region cannot be empty" if region.nil? || region.empty? end |