Class: LlmsTxt::Config

Inherits:
Object
  • Object
show all
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.

Examples:

Load default config file

config = LlmsTxt::Config.new

Load specific config file

config = LlmsTxt::Config.new('my-config.yml')

Access config values

config['base_url']        # => "https://myproject.io"
config.dig('output')      # => "llms.txt"

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataHash (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 merge_with_options(options)
  # CLI options override config file, config file provides defaults
  {
    docs: options[:docs] || self['docs'] || '.',
    base_url: options[:base_url] || self['base_url'],
    title: options[:title] || self['title'],
    description: options[:description] || self['description'],
    output: options[:output] || self['output'] || 'llms.txt',
    convert_urls: if options.key?(:convert_urls)
                    options[:convert_urls]
                  else
                    self['convert_urls'] || false
                  end,
    verbose: options.key?(:verbose) ? options[:verbose] : (self['verbose'] || false),
    # Bulk transformation options
    suffix: options[:suffix] || self['suffix'] || '.llm',
    excludes: options[:excludes] || self['excludes'] || [],
    bulk: options.key?(:bulk) ? options[:bulk] : (self['bulk'] || false)
  }
end