Class: Defmastership::Modifier::UpdateEref

Inherits:
Object
  • Object
show all
Includes:
ModifierCommon
Defined in:
lib/defmastership/modifier/update_eref_common.rb

Overview

Update external refs version

Direct Known Subclasses

UpdateErefChecksum, UpdateErefVersion

Instance Attribute Summary

Attributes included from ModifierCommon

#changes, #config

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModifierCommon

#method_missing, #respond_to_missing?, #setup_modifier_module

Constructor Details

#initialize(config) ⇒ UpdateEref

Returns a new instance of UpdateEref.

Parameters:

  • config (YAML)

    the modifier’s provided configurations



23
24
25
26
27
# File 'lib/defmastership/modifier/update_eref_common.rb', line 23

def initialize(config)
  @the_ref_document = Document.new

  setup_modifier_module(config)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Defmastership::Modifier::ModifierCommon

Class Method Details

.default_configHash{Symbol => Object}

Returns the default configuration.

Returns:

  • (Hash{Symbol => Object})

    the default configuration



15
16
17
18
19
20
# File 'lib/defmastership/modifier/update_eref_common.rb', line 15

def self.default_config
  {
    eref_type: '',
    ref_document: ''
  }
end

Instance Method Details

#do_modifications(adoc_sources) ⇒ Object

Apply the modifier on all provided asciidoc sources based on modifier’s self.replacement_methods list

Parameters:

  • adoc_sources (Hash{String => String})

    asciidoc sources

    • :key filename

    • :value file content



35
36
37
38
39
# File 'lib/defmastership/modifier/update_eref_common.rb', line 35

def do_modifications(adoc_sources)
  Array(ref_document).each { |ref_doc| the_ref_document.parse_file_with_preprocessor(ref_doc) }

  super
end

#replace_erefs(_filename, line) ⇒ String

Replace the definition’s external ref in the line if relevant

Parameters:

  • _filename (String)

    the filename of the file beeing modified

  • line (String)

    the current line

Returns:

  • (String)

    the modified line



46
47
48
49
50
51
52
53
# File 'lib/defmastership/modifier/update_eref_common.rb', line 46

def replace_erefs(_filename, line)
  match = line.match(Core::DMRegexp::EREF_DEF)
  # Return early if there's no match or the type is not valid
  return line unless match && eref_type_valid?(match[:reference])

  # Delegate the actual replacement to a separate method
  perform_replacement(line, match[:extrefs])
end