Class: DefMastership::UpdateDefChecksumLineModifier

Inherits:
LineModifierBase show all
Defined in:
lib/defmastership/update_def_checksum_line_modifier.rb

Overview

modify one line after another

Instance Attribute Summary collapse

Attributes inherited from LineModifierBase

#changes, #config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LineModifierBase

#from_config, #method_missing, #respond_to_missing?

Constructor Details

#initializeUpdateDefChecksumLineModifier

Returns a new instance of UpdateDefChecksumLineModifier.



13
14
15
16
17
18
# File 'lib/defmastership/update_def_checksum_line_modifier.rb', line 13

def initialize
  super
  @config = {
    def_type: ''
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DefMastership::LineModifierBase

Instance Attribute Details

#documentObject

Returns the value of attribute document.



7
8
9
# File 'lib/defmastership/update_def_checksum_line_modifier.rb', line 7

def document
  @document
end

Class Method Details

.from_config(hash) ⇒ Object



9
10
11
# File 'lib/defmastership/update_def_checksum_line_modifier.rb', line 9

def self.from_config(hash)
  new.from_config(hash)
end

Instance Method Details

#matched?(line) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
# File 'lib/defmastership/update_def_checksum_line_modifier.rb', line 31

def matched?(line)
  return if line.commented?
  return unless line =~ DMRegexp::DEFINITION

  Regexp.last_match
end

#replace(line) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/defmastership/update_def_checksum_line_modifier.rb', line 20

def replace(line)
  match = matched?(line)

  return line unless match
  return line unless match[:type] == def_type

  line.gsub(Regexp.new("#{match[:reference]}#{DMRegexp::DEF_VERSION_AND_CHECKSUM}")) do
    "#{match[:reference]}(#{match[:explicit_version]}#{@document.ref_to_def(match[:reference]).sha256})"
  end
end