Class: Chiridion::Config

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

Overview

Configuration for documentation generation.

Chiridion can be configured globally or per-engine instance. All options have sensible defaults for common Ruby project layouts.

Examples:

Global configuration

Chiridion.configure do |config|
  config.output = 'docs/sys'
  config.namespace_filter = 'MyProject::'
  config.github_repo = 'user/repo'
end

Per-project configuration file

# .chiridion.yml
output: docs/sys
namespace_filter: MyProject::
github_repo: user/repo
include_specs: true

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/chiridion/config.rb', line 71

def initialize
  @root                    = Dir.pwd
  @source_path             = "lib"
  @output                  = "docs/sys"
  @namespace_filter        = nil
  @namespace_strip         = nil
  @github_repo             = nil
  @github_branch           = "main"
  @include_specs           = false
  @spec_path               = "test"
  @rbs_path                = "sig"
  @verbose                 = false
  @logger                  = nil
  @inline_source_threshold = 10
  @output_mode             = :per_file
end

Instance Attribute Details

#github_branchString

Returns Git branch for source links.

Returns:

  • (String)

    Git branch for source links



46
47
48
# File 'lib/chiridion/config.rb', line 46

def github_branch
  @github_branch
end

#github_repoString?

Returns GitHub repository for source links (e.g., “user/repo”).

Returns:

  • (String, nil)

    GitHub repository for source links (e.g., “user/repo”)



43
44
45
# File 'lib/chiridion/config.rb', line 43

def github_repo
  @github_repo
end

#include_specsBoolean

Returns Whether to extract examples from spec files.

Returns:

  • (Boolean)

    Whether to extract examples from spec files



49
50
51
# File 'lib/chiridion/config.rb', line 49

def include_specs
  @include_specs
end

#inline_source_thresholdInteger?

Returns Maximum body lines for inline source display. Methods with body <= this many lines show their implementation inline. Set to nil or 0 to disable inline source. Default: 10.

Returns:

  • (Integer, nil)

    Maximum body lines for inline source display. Methods with body <= this many lines show their implementation inline. Set to nil or 0 to disable inline source. Default: 10.



66
67
68
# File 'lib/chiridion/config.rb', line 66

def inline_source_threshold
  @inline_source_threshold
end

#logger#info, ...

Returns Logger for output messages.

Returns:

  • (#info, #warn, #error, nil)

    Logger for output messages



61
62
63
# File 'lib/chiridion/config.rb', line 61

def logger
  @logger
end

#namespace_filterString?

Returns Namespace prefix to filter (e.g., “MyProject::”) Only classes/modules starting with this prefix are documented. If nil, all classes are included.

Returns:

  • (String, nil)

    Namespace prefix to filter (e.g., “MyProject::”) Only classes/modules starting with this prefix are documented. If nil, all classes are included.



36
37
38
# File 'lib/chiridion/config.rb', line 36

def namespace_filter
  @namespace_filter
end

#namespace_stripObject

Namespace prefix to strip from output paths. Defaults to namespace_filter if not explicitly set.



90
# File 'lib/chiridion/config.rb', line 90

def namespace_strip = @namespace_strip || @namespace_filter

#outputString

Returns Output directory for generated docs.

Returns:

  • (String)

    Output directory for generated docs



31
32
33
# File 'lib/chiridion/config.rb', line 31

def output
  @output
end

#output_modeSymbol

Returns Output organization strategy (:per_class or :per_file).

Returns:

  • (Symbol)

    Output organization strategy (:per_class or :per_file)



69
70
71
# File 'lib/chiridion/config.rb', line 69

def output_mode
  @output_mode
end

#rbs_pathString

Returns Path to RBS signatures directory (relative to root).

Returns:

  • (String)

    Path to RBS signatures directory (relative to root)



55
56
57
# File 'lib/chiridion/config.rb', line 55

def rbs_path
  @rbs_path
end

#rootString

Returns Root directory of the project (defaults to current directory).

Returns:

  • (String)

    Root directory of the project (defaults to current directory)



25
26
27
# File 'lib/chiridion/config.rb', line 25

def root
  @root
end

#source_pathString

Returns Source directory to document (relative to root).

Returns:

  • (String)

    Source directory to document (relative to root)



28
29
30
# File 'lib/chiridion/config.rb', line 28

def source_path
  @source_path
end

#spec_pathString

Returns Path to test directory (relative to root).

Returns:

  • (String)

    Path to test directory (relative to root)



52
53
54
# File 'lib/chiridion/config.rb', line 52

def spec_path
  @spec_path
end

#verboseBoolean

Returns Verbose output during generation.

Returns:

  • (Boolean)

    Verbose output during generation



58
59
60
# File 'lib/chiridion/config.rb', line 58

def verbose
  @verbose
end

Instance Method Details

#full_output_pathString

Returns Full path to output directory.

Returns:

  • (String)

    Full path to output directory



120
# File 'lib/chiridion/config.rb', line 120

def full_output_path = File.join(root, output)

#full_rbs_pathString

Returns Full path to RBS directory.

Returns:

  • (String)

    Full path to RBS directory



126
# File 'lib/chiridion/config.rb', line 126

def full_rbs_path = File.join(root, rbs_path)

#full_source_pathString

Returns Full path to source directory.

Returns:

  • (String)

    Full path to source directory



117
# File 'lib/chiridion/config.rb', line 117

def full_source_path = File.join(root, source_path)

#full_spec_pathString

Returns Full path to spec directory.

Returns:

  • (String)

    Full path to spec directory



123
# File 'lib/chiridion/config.rb', line 123

def full_spec_path = File.join(root, spec_path)

#load_file(path) ⇒ Config

Load configuration from a YAML file.

Parameters:

  • path (String)

    Path to YAML configuration file

Returns:



96
97
98
99
100
101
102
# File 'lib/chiridion/config.rb', line 96

def load_file(path)
  return self unless File.exist?(path)

  require "yaml"
  data = YAML.safe_load_file(path, symbolize_names: true)
  load_hash(data)
end

#load_hash(data) ⇒ Config

Load configuration from a hash.

Parameters:

  • data (Hash)

    Configuration values

Returns:



108
109
110
111
112
113
114
# File 'lib/chiridion/config.rb', line 108

def load_hash(data)
  data.each do |key, value|
    setter = :"#{key}="
    public_send(setter, value) if respond_to?(setter)
  end
  self
end