Class: DocGuard::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/doc_guard/config.rb

Overview

Handles configuration for DocGuard by loading values from:

  • Explicit parameters (highest priority)

  • Environment variables

  • YAML config file (.doc_guard.yml)

  • Internal defaults (lowest priority)

This class supports usage in CLI, CI/CD pipelines, or manual scripts without requiring any Rails integration.

Constant Summary collapse

DEFAULT_CONFIG_FILE_PATH =
".doc_guard.yml"
DEFAULT_DIGESTS_STORE_FILE_PATH =
".doc_guard_digests.json"
DEFAULT_DOCUMENTATION_PATH =
"docs"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(digests_store_file_path: nil, documentation_path: nil, config_file_path: nil) ⇒ Config

Initialize configuration for DocGuard.

You can pass ‘nil` to `digests_store_file_path` or `documentation_path` to allow fallback to ENV, config file, or defaults.

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

Examples:

Basic usage

DocGuard::Config.new(
  digests_store_file_path: nil,
  documentation_path: nil
)

Parameters:

  • digests_store_file_path (String, nil) (defaults to: nil)

    Optional override path for storing digests. Defaults to ‘.doc_guard_digests.json`.

  • documentation_path (String, nil) (defaults to: nil)

    Optional override path to the documentation folder. Defaults to ‘docs`.

  • config_file_path (String, nil) (defaults to: nil)

    Optional override path to the config file (YAML). Defaults to ‘.doc_guard.yml`.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/doc_guard/config.rb', line 31

def initialize(digests_store_file_path: nil, documentation_path: nil, config_file_path: nil)
  @config_file_path =
    config_file_path ||
    ENV["DOC_GUARD_CONFIG_FILE_PATH"] ||
    DEFAULT_CONFIG_FILE_PATH

  config = load_config_file(@config_file_path)

  @documentation_path =
    documentation_path ||
    ENV["DOC_GUARD_DOCUMENTATION_PATH"] ||
    config["documentation_path"] ||
    DEFAULT_DOCUMENTATION_PATH

  @digests_store_file_path =
    digests_store_file_path ||
    ENV["DOC_GUARD_DIGESTS_STORE_FILE_PATH"] ||
    config["digests_store_file_path"] ||
    DEFAULT_DIGESTS_STORE_FILE_PATH
end

Instance Attribute Details

#config_file_pathString (readonly)

Returns Resolved path to the digests JSON file.

Returns:

  • (String)

    Resolved path to the digests JSON file.



60
61
62
# File 'lib/doc_guard/config.rb', line 60

def config_file_path
  @config_file_path
end

#digests_store_file_pathString (readonly)

Returns Resolved path to the digests JSON file.

Returns:

  • (String)

    Resolved path to the digests JSON file.



57
58
59
# File 'lib/doc_guard/config.rb', line 57

def digests_store_file_path
  @digests_store_file_path
end

#documentation_pathString (readonly)

Returns Resolved documentation path.

Returns:

  • (String)

    Resolved documentation path.



54
55
56
# File 'lib/doc_guard/config.rb', line 54

def documentation_path
  @documentation_path
end