Class: LlmsTxt::Config
- Inherits:
-
Object
- Object
- LlmsTxt::Config
- Defined in:
- lib/llms_txt/config.rb
Overview
Simple configuration loader for llms-txt.yml files
Loads YAML configuration files and provides a simple interface for accessing configuration values. Automatically looks for config files in the current directory if none specified.
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
The loaded configuration data.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Access configuration value by key.
-
#dig(*keys) ⇒ Object?
Access nested configuration values.
-
#exists? ⇒ Boolean
Check if a config file was found and exists.
-
#initialize(config_file = nil) ⇒ Config
constructor
Initialize a new configuration loader.
-
#merge_with_options(options) ⇒ Hash
Merge config file values with CLI options.
Constructor Details
#initialize(config_file = nil) ⇒ Config
Initialize a new configuration loader
29 30 31 32 |
# File 'lib/llms_txt/config.rb', line 29 def initialize(config_file = nil) @config_file = config_file || find_config_file @data = load_config end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns the loaded configuration data.
24 25 26 |
# File 'lib/llms_txt/config.rb', line 24 def data @data end |
Instance Method Details
#[](key) ⇒ Object?
Access configuration value by key
38 39 40 |
# File 'lib/llms_txt/config.rb', line 38 def [](key) data[key.to_s] end |
#dig(*keys) ⇒ Object?
Access nested configuration values
46 47 48 |
# File 'lib/llms_txt/config.rb', line 46 def dig(*keys) data.dig(*keys.map(&:to_s)) end |
#exists? ⇒ Boolean
Check if a config file was found and exists
81 82 83 |
# File 'lib/llms_txt/config.rb', line 81 def exists? @config_file && File.exist?(@config_file) end |
#merge_with_options(options) ⇒ Hash
Merge config file values with CLI options
CLI options take precedence over config file values. Config file provides defaults for any options not specified via CLI.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/llms_txt/config.rb', line 57 def () # CLI options override config file, config file provides defaults { docs: [:docs] || self['docs'] || '.', base_url: [:base_url] || self['base_url'], title: [:title] || self['title'], description: [:description] || self['description'], output: [:output] || self['output'] || 'llms.txt', convert_urls: if .key?(:convert_urls) [:convert_urls] else self['convert_urls'] || false end, verbose: .key?(:verbose) ? [:verbose] : (self['verbose'] || false), # Bulk transformation options suffix: [:suffix] || self['suffix'] || '.llm', excludes: [:excludes] || self['excludes'] || [], bulk: .key?(:bulk) ? [:bulk] : (self['bulk'] || false) } end |