Class: Vectory::Configuration
- Inherits:
-
Object
- Object
- Vectory::Configuration
- Defined in:
- lib/vectory/configuration.rb
Overview
Configuration for Vectory
Provides centralized configuration for tool paths, timeouts, caching, etc. Can be loaded from environment variables or a configuration file.
Constant Summary collapse
- DEFAULT_TIMEOUT =
Default timeout for external tool execution (seconds)
120- DEFAULT_CACHE_TTL =
Default cache TTL for memoized values (seconds)
300- DEFAULT_TEMP_DIR =
Default temporary directory
nil
Instance Attribute Summary collapse
-
#cache_enabled ⇒ Object
Use system default.
-
#cache_ttl ⇒ Object
Use system default.
-
#ghostscript_path ⇒ Object
Use system default.
-
#inkscape_path ⇒ Object
Use system default.
-
#temp_dir ⇒ Object
Use system default.
-
#timeout ⇒ Object
Use system default.
-
#verbose_logging ⇒ Object
Use system default.
Class Method Summary collapse
-
.instance ⇒ Vectory::Configuration
Get the singleton instance.
-
.load_from_environment ⇒ self
Load configuration from environment variables.
-
.load_from_file(path) ⇒ self
Load configuration from a YAML file.
-
.reset! ⇒ Object
private
Reset the configuration to defaults.
Instance Method Summary collapse
-
#caching_enabled? ⇒ Boolean
Check if caching is enabled.
-
#effective_ghostscript_path ⇒ String?
Get the Ghostscript path (custom or auto-detected).
-
#effective_inkscape_path ⇒ String?
Get the Inkscape path (custom or auto-detected).
-
#initialize ⇒ Configuration
constructor
Initialize configuration with default values.
-
#temporary_directory ⇒ String
Get the temporary directory.
-
#to_h ⇒ Hash
Export configuration as a hash.
-
#validate! ⇒ Boolean
Validate the configuration.
-
#verbose_logging? ⇒ Boolean
Check if verbose logging is enabled.
Constructor Details
#initialize ⇒ Configuration
Initialize configuration with default values
43 44 45 46 47 48 49 50 51 |
# File 'lib/vectory/configuration.rb', line 43 def initialize @timeout = DEFAULT_TIMEOUT @cache_ttl = DEFAULT_CACHE_TTL @cache_enabled = true @temp_dir = DEFAULT_TEMP_DIR @verbose_logging = false @inkscape_path = nil @ghostscript_path = nil end |
Instance Attribute Details
#cache_enabled ⇒ Object
Use system default
25 26 27 |
# File 'lib/vectory/configuration.rb', line 25 def cache_enabled @cache_enabled end |
#cache_ttl ⇒ Object
Use system default
25 26 27 |
# File 'lib/vectory/configuration.rb', line 25 def cache_ttl @cache_ttl end |
#ghostscript_path ⇒ Object
Use system default
25 26 27 |
# File 'lib/vectory/configuration.rb', line 25 def ghostscript_path @ghostscript_path end |
#inkscape_path ⇒ Object
Use system default
25 26 27 |
# File 'lib/vectory/configuration.rb', line 25 def inkscape_path @inkscape_path end |
#temp_dir ⇒ Object
Use system default
25 26 27 |
# File 'lib/vectory/configuration.rb', line 25 def temp_dir @temp_dir end |
#timeout ⇒ Object
Use system default
25 26 27 |
# File 'lib/vectory/configuration.rb', line 25 def timeout @timeout end |
#verbose_logging ⇒ Object
Use system default
25 26 27 |
# File 'lib/vectory/configuration.rb', line 25 def verbose_logging @verbose_logging end |
Class Method Details
.instance ⇒ Vectory::Configuration
Get the singleton instance
31 32 33 |
# File 'lib/vectory/configuration.rb', line 31 def self.instance @instance ||= new end |
.load_from_environment ⇒ self
Load configuration from environment variables
Supported environment variables:
-
VECTORY_INKSCAPE_PATH: Path to Inkscape executable
-
VECTORY_GHOSTSCRIPT_PATH: Path to Ghostscript executable
-
VECTORY_TIMEOUT: Timeout for external tools (default: 120)
-
VECTORY_CACHE_TTL: Cache TTL in seconds (default: 300)
-
VECTORY_CACHE_ENABLED: Enable/disable caching (default: true)
-
VECTORY_TEMP_DIR: Temporary directory path
-
VECTORY_VERBOSE: Enable verbose logging (default: false)
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vectory/configuration.rb', line 65 def self.load_from_environment config = instance config.inkscape_path = ENV["VECTORY_INKSCAPE_PATH"] if ENV["VECTORY_INKSCAPE_PATH"] config.ghostscript_path = ENV["VECTORY_GHOSTSCRIPT_PATH"] if ENV["VECTORY_GHOSTSCRIPT_PATH"] config.timeout = ENV["VECTORY_TIMEOUT"]&.to_i || config.timeout config.cache_ttl = ENV["VECTORY_CACHE_TTL"]&.to_i || config.cache_ttl config.cache_enabled = ENV["VECTORY_CACHE_ENABLED"] != "false" config.temp_dir = ENV["VECTORY_TEMP_DIR"] if ENV["VECTORY_TEMP_DIR"] config.verbose_logging = ENV["VECTORY_VERBOSE"] == "true" config end |
.load_from_file(path) ⇒ self
Load configuration from a YAML file
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/vectory/configuration.rb', line 84 def self.load_from_file(path) require "yaml" config_data = YAML.load_file(path) config = instance config.inkscape_path = config_data["inkscape_path"] if config_data["inkscape_path"] config.ghostscript_path = config_data["ghostscript_path"] if config_data["ghostscript_path"] config.timeout = config_data["timeout"] || config.timeout config.cache_ttl = config_data["cache_ttl"] || config.cache_ttl config.cache_enabled = config_data.fetch("cache_enabled", config.cache_enabled) config.temp_dir = config_data["temp_dir"] || config.temp_dir config.verbose_logging = config_data.fetch("verbose_logging", config.verbose_logging) config 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 configuration to defaults
38 39 40 |
# File 'lib/vectory/configuration.rb', line 38 def self.reset! @instance = new end |
Instance Method Details
#caching_enabled? ⇒ Boolean
Check if caching is enabled
134 135 136 |
# File 'lib/vectory/configuration.rb', line 134 def caching_enabled? @cache_enabled end |
#effective_ghostscript_path ⇒ String?
Get the Ghostscript path (custom or auto-detected)
127 128 129 |
# File 'lib/vectory/configuration.rb', line 127 def effective_ghostscript_path @ghostscript_path end |
#effective_inkscape_path ⇒ String?
Get the Inkscape path (custom or auto-detected)
120 121 122 |
# File 'lib/vectory/configuration.rb', line 120 def effective_inkscape_path @inkscape_path end |
#temporary_directory ⇒ String
Get the temporary directory
141 142 143 |
# File 'lib/vectory/configuration.rb', line 141 def temporary_directory @temp_dir || Dir.tmpdir end |
#to_h ⇒ Hash
Export configuration as a hash
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/vectory/configuration.rb', line 105 def to_h { inkscape_path: @inkscape_path, ghostscript_path: @ghostscript_path, timeout: @timeout, cache_ttl: @cache_ttl, cache_enabled: @cache_enabled, temp_dir: @temp_dir, verbose_logging: @verbose_logging, } end |
#validate! ⇒ Boolean
Validate the configuration
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/vectory/configuration.rb', line 156 def validate! errors = [] if @timeout && @timeout <= 0 errors << "timeout must be positive, got: #{@timeout}" end if @cache_ttl&.negative? errors << "cache_ttl must be non-negative, got: #{@cache_ttl}" end if @temp_dir && !File.directory?(@temp_dir) errors << "temp_dir does not exist: #{@temp_dir}" end return true if errors.empty? raise ArgumentError, "Invalid configuration:\n - #{errors.join("\n - ")}" end |
#verbose_logging? ⇒ Boolean
Check if verbose logging is enabled
148 149 150 |
# File 'lib/vectory/configuration.rb', line 148 def verbose_logging? @verbose_logging end |