Module: Yaml::Converter::Config
- Defined in:
- lib/yaml/converter/config.rb
Overview
Central configuration handling: merges explicit options with ENV and defaults.
Use Config.resolve to obtain the finalized options hash.
Constant Summary collapse
- DEFAULTS =
{ max_line_length: 70, truncate: true, margin_notes: :auto, # :auto | :inline | :ignore validate: true, use_pandoc: false, pandoc_args: ["-N", "--toc"], pandoc_path: nil, html_theme: :basic, pdf_page_size: "LETTER", pdf_margin: [36, 36, 36, 36], # top,right,bottom,left points (0.5") pdf_title_font_size: 14, pdf_body_font_size: 11, pdf_yaml_font_size: 9, pdf_two_column_notes: false, current_date: Date.today, # allows injection for deterministic tests emit_footer: true, # Streaming options (Phase 3 feature now implemented): streaming: false, # force streaming mode even for small files streaming_threshold_bytes: 5_000_000, # auto-enable streaming for large files when not forced }.freeze
- ENV_MAP =
{ max_line_length: "YAML_CONVERTER_MAX_LINE_LEN", truncate: "YAML_CONVERTER_TRUNCATE", margin_notes: "YAML_CONVERTER_MARGIN_NOTES", validate: "YAML_CONVERTER_VALIDATE", use_pandoc: "YAML_CONVERTER_USE_PANDOC", pdf_page_size: "YAML_CONVERTER_PDF_PAGE_SIZE", pdf_title_font_size: "YAML_CONVERTER_PDF_TITLE_FONT_SIZE", pdf_body_font_size: "YAML_CONVERTER_PDF_BODY_FONT_SIZE", pdf_yaml_font_size: "YAML_CONVERTER_PDF_YAML_FONT_SIZE", pdf_two_column_notes: "YAML_CONVERTER_PDF_TWO_COLUMN_NOTES", emit_footer: "YAML_CONVERTER_EMIT_FOOTER", streaming: "YAML_CONVERTER_STREAMING", streaming_threshold_bytes: "YAML_CONVERTER_STREAMING_THRESHOLD_BYTES", }.freeze
- BOOLEAN_KEYS =
%i[truncate validate use_pandoc pdf_two_column_notes emit_footer streaming].freeze
Class Method Summary collapse
-
.coerce_env_value(key, value) ⇒ Object
Coerce ENV string values into typed Ruby objects.
-
.normalize(opts) ⇒ Hash
Normalize symbolic values loaded from ENV.
-
.resolve(options = {}) ⇒ Hash
Merge caller options with environment overrides and defaults.
Class Method Details
.coerce_env_value(key, value) ⇒ Object
Coerce ENV string values into typed Ruby objects.
86 87 88 89 90 91 92 93 94 |
# File 'lib/yaml/converter/config.rb', line 86 def coerce_env_value(key, value) if BOOLEAN_KEYS.include?(key) %w[1 true yes on].include?(value.to_s.downcase) elsif key == :max_line_length || key == :streaming_threshold_bytes value.to_i else value end end |
.normalize(opts) ⇒ Hash
Normalize symbolic values loaded from ENV.
73 74 75 76 77 78 79 80 |
# File 'lib/yaml/converter/config.rb', line 73 def normalize(opts) opts[:margin_notes] = opts[:margin_notes].to_sym if opts[:margin_notes].is_a?(String) opts[:html_theme] = opts[:html_theme].to_sym if opts[:html_theme].is_a?(String) if opts[:streaming_threshold_bytes].is_a?(String) opts[:streaming_threshold_bytes] = opts[:streaming_threshold_bytes].to_i end opts end |
.resolve(options = {}) ⇒ Hash
Merge caller options with environment overrides and defaults.
Environment bools accept values: 1, true, yes, on (case-insensitive).
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/yaml/converter/config.rb', line 56 def resolve( = {}) opts = DEFAULTS.dup ENV_MAP.each do |key, env_key| val = ENV[env_key] next if val.nil? opts[key] = coerce_env_value(key, val) end .each do |k, v| opts[k] = v unless v.nil? end normalize(opts) end |