Module: GrafanaReporter::Asciidoctor::ProcessorMixin

Overview

This module contains common methods for all asciidoctor extensions.

Instance Method Summary collapse

Instance Method Details

#build_attribute_hash(document_hash, item_hash) ⇒ Hash

Merges the given hashes to a common attribute Hash. It respects the priorities of the hashes and the object and allows only valid variables to be used.

Parameters:

  • document_hash (Hash)

    variables from report template level

  • item_hash (Hash)

    variables from item configuration level, i.e. specific call, which may override document

Returns:

  • (Hash)

    containing accepted variable names including values



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/grafana_reporter/asciidoctor/processor_mixin.rb', line 27

def build_attribute_hash(document_hash, item_hash)
  result = {}

  result['grafana_report_timestamp'] = document_hash['localdatetime']
  result.merge!(document_hash.select do |k, _v|
    k =~ /^var-/ ||
    k =~ /^(?:from|to)$/ ||
    k =~ /^grafana_default_(?:from_timezone|to_timezone|timeout)$/
  end)

  result.merge!(item_hash.select do |k, _v|
    # TODO: specify accepted options for each processor class individually
    k =~ /^(?:var-|render-)/ ||
    k =~ /^(?:timeout|from|to)$/ ||
    k =~ /filter_columns|format|replace_values_.*|transpose|from_timezone|
         to_timezone|result_type|query|table_formatter|include_headline|
         column_divider|row_divider|instant|interval|verbose_log/x
  end)

  result
end

#build_demo_entry(panel) ⇒ String

This method is called if a demo report shall be built for the given Grafana::Panel.

Parameters:

  • panel (Grafana::Panel)

    panel object, for which a demo entry shall be created.

Returns:

  • (String)

    String containing the entry, or nil if not possible for given panel

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/grafana_reporter/asciidoctor/processor_mixin.rb', line 18

def build_demo_entry(panel)
  raise NotImplementedError
end

#current_report(report) ⇒ ::Asciidoctor::Extensions::Processor

Used when initializing a object instance, to set the report object, which is currently in progress.

Parameters:

Returns:

  • (::Asciidoctor::Extensions::Processor)

    self



10
11
12
13
# File 'lib/grafana_reporter/asciidoctor/processor_mixin.rb', line 10

def current_report(report)
  @report = report
  self
end