Class: Konfig::Exporters::EnvVarsAsMarkdown

Inherits:
Abstract
  • Object
show all
Defined in:
lib/konfig/exporters/env_vars_as_markdown.rb

Overview

This export will create a markdown document containing all configuration variables as defined the schema shown as environment variables.

Instance Method Summary collapse

Methods inherited from Abstract

#initialize

Constructor Details

This class inherits a constructor from Konfig::Exporters::Abstract

Instance Method Details

#exportObject

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/konfig/exporters/env_vars_as_markdown.rb', line 14

def export
  contents = []
  contents << "# #{options[:title] || 'Environment Variables'}"
  contents << ''
  contents << (options[:introduction] ||
      'This document contains all the environment variables which are available for this application.')
  contents << ''
  contents << '| Name | Type | Description | Default |'
  contents << '| ---- | ---- | ----------- | ------- |'
  path = []
  @schema.groups.each do |group_name, group|
    path << group_name
    group.attributes.each do |name, attr|
      env_var = Sources::Environment.path_to_env_var(path + [name])
      type = attr.array? ? "Array of #{attr.type}s" : attr.type.to_s.capitalize
      contents << "| `#{env_var}` | #{type} | #{attr.description} | #{attr.default} |"
    end
    path.pop
  end
  contents.join("\n") + "\n"
end