Class: LlmDocsBuilder::Config
- Inherits:
-
Object
- Object
- LlmDocsBuilder::Config
- Defined in:
- lib/llm_docs_builder/config.rb
Overview
Simple configuration loader for llm-docs-builder.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/llm_docs_builder/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/llm_docs_builder/config.rb', line 24 def data @data end |
Instance Method Details
#[](key) ⇒ Object?
Access configuration value by key
38 39 40 |
# File 'lib/llm_docs_builder/config.rb', line 38 def [](key) data[key.to_s] end |
#dig(*keys) ⇒ Object?
Access nested configuration values
46 47 48 |
# File 'lib/llm_docs_builder/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
220 221 222 |
# File 'lib/llm_docs_builder/config.rb', line 220 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.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/llm_docs_builder/config.rb', line 90 def () # CLI options override config file, config file provides defaults { docs: if .key?(:docs) [:docs] else self['docs'] || '.' end, base_url: [:base_url] || self['base_url'], title: [:title] || self['title'], description: [:description] || self['description'], body: [:body] || self['body'], output: [:output] || self['output'] || 'llms.txt', convert_urls: if .key?(:convert_urls) [:convert_urls] else self['convert_urls'] || false end, remove_comments: if .key?(:remove_comments) [:remove_comments] elsif !self['remove_comments'].nil? self['remove_comments'] else true end, normalize_whitespace: if .key?(:normalize_whitespace) [:normalize_whitespace] elsif !self['normalize_whitespace'].nil? self['normalize_whitespace'] else true end, remove_badges: if .key?(:remove_badges) [:remove_badges] elsif !self['remove_badges'].nil? self['remove_badges'] else true end, remove_frontmatter: if .key?(:remove_frontmatter) [:remove_frontmatter] elsif !self['remove_frontmatter'].nil? self['remove_frontmatter'] else true 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), include_hidden: .key?(:include_hidden) ? [:include_hidden] : (self['include_hidden'] || false), # New compression options remove_code_examples: if .key?(:remove_code_examples) [:remove_code_examples] else self['remove_code_examples'] || false end, remove_images: if .key?(:remove_images) [:remove_images] else self['remove_images'] || false end, simplify_links: if .key?(:simplify_links) [:simplify_links] else self['simplify_links'] || false end, remove_blockquotes: if .key?(:remove_blockquotes) [:remove_blockquotes] else self['remove_blockquotes'] || false end, generate_toc: if .key?(:generate_toc) [:generate_toc] else self['generate_toc'] || false end, custom_instruction: [:custom_instruction] || self['custom_instruction'], remove_stopwords: if .key?(:remove_stopwords) [:remove_stopwords] else self['remove_stopwords'] || false end, remove_duplicates: if .key?(:remove_duplicates) [:remove_duplicates] else self['remove_duplicates'] || false end, # New RAG enhancement options normalize_headings: if .key?(:normalize_headings) [:normalize_headings] else self['normalize_headings'] || false end, heading_separator: [:heading_separator] || self['heading_separator'] || ' / ', include_metadata: if .key?(:include_metadata) [:include_metadata] else self['include_metadata'] || false end, include_tokens: if .key?(:include_tokens) [:include_tokens] else self['include_tokens'] || false end, include_timestamps: if .key?(:include_timestamps) [:include_timestamps] else self['include_timestamps'] || false end, include_priority: if .key?(:include_priority) [:include_priority] else self['include_priority'] || false end, calculate_compression: if .key?(:calculate_compression) [:calculate_compression] else self['calculate_compression'] || false end }.tap do |merged| merged[:content] = [:content] if .key?(:content) merged[:source_url] = [:source_url] if .key?(:source_url) end end |