Module: DocOpsLab::Dev::DataUtils

Defined in:
lib/docopslab/dev/data_utils.rb

Overview

Utilities for loading and caching project-level data for use in Liquid template rendering (Sync/Cast) and other data-driven operations.

Class Method Summary collapse

Class Method Details

.project_attributesHash{String => String}

Lazily load and cache the README.adoc document attributes.

Available in Liquid templates as data.project.attributes.<key>. Asciidoctor built-in attributes are filtered out; only user-defined

string attributes are returned.

Returns:

  • (Hash{String => String})


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/docopslab/dev/data_utils.rb', line 16

def project_attributes
  return @project_attributes if defined?(@project_attributes)

  readme = 'README.adoc'
  unless File.exist?(readme)
    @project_attributes = {}
    return @project_attributes
  end

  require 'sourcerer/asciidoc'
  raw = Sourcerer::AsciiDoc.load_attributes(readme)
  @project_attributes = raw.select do |k, v|
    v.is_a?(String) && !v.empty? && !k.start_with?('asciidoctor')
  end
rescue StandardError => e
  warn "⚠️  Could not load README.adoc attributes: #{e.message}"
  @project_attributes = {}
end

.reset_project_attributes!Object

Reset the cached project attributes (useful in tests or after file changes).



36
37
38
# File 'lib/docopslab/dev/data_utils.rb', line 36

def reset_project_attributes!
  remove_instance_variable(:@project_attributes) if defined?(@project_attributes)
end