Class: Semverve::VersionCodeReferences

Inherits:
Object
  • Object
show all
Defined in:
lib/semverve/version_code_references.rb

Overview

Finds and updates safe version literals in configured code files.

Defined Under Namespace

Classes: Finding, FixResult

Constant Summary collapse

RUBY_ASSIGNMENT_PATTERN =

Ruby assignments that are safe enough to rewrite automatically.

Returns:

  • (Regexp)
Configuration::DEFAULT_VERSION_CODE_REFERENCE_PATTERN

Instance Method Summary collapse

Constructor Details

#initialize(configuration, current_version) ⇒ Semverve::VersionCodeReferences

Initializes code version literal scanning.

Parameters:



96
97
98
99
# File 'lib/semverve/version_code_references.rb', line 96

def initialize(configuration, current_version)
  @configuration = configuration
  @current_version = current_version
end

Instance Method Details

#findingsArray<Semverve::VersionCodeReferences::Finding>

Code version literal findings in configured files.



105
106
107
# File 'lib/semverve/version_code_references.rb', line 105

def findings
  files.flat_map { |path| findings_for_file(path) }
end

#fixSemverve::VersionCodeReferences::FixResult

Replaces found code version literals with the current version.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/semverve/version_code_references.rb', line 113

def fix
  changed_files = []
  replacement_count = 0

  files.each do |path|
    content = File.read(path)
    fixed, count = fixed_content(content)

    next if count.zero?

    File.write(path, fixed)
    changed_files << relative_path(path)
    replacement_count += count
  end

  FixResult.new(changed_files: changed_files, replacement_count: replacement_count)
end