Class: Semverve::VersionCodeReferences
- Inherits:
-
Object
- Object
- Semverve::VersionCodeReferences
- Defined in:
- lib/semverve/version_code_references.rb
Overview
Finds and updates safe version literals in configured code files.
Defined Under Namespace
Constant Summary collapse
- IGNORE_MARKER =
Marker that suppresses version-reference findings.
"semverve:ignore-version-reference"- RUBY_ASSIGNMENT_PATTERN =
Ruby assignments that are safe enough to rewrite automatically.
Configuration::DEFAULT_VERSION_CODE_REFERENCE_PATTERN
Instance Method Summary collapse
-
#findings ⇒ Array<Semverve::VersionCodeReferences::Finding>
Code version literal findings in configured files.
-
#fix ⇒ Semverve::VersionCodeReferences::FixResult
Replaces found code version literals with the current version.
-
#initialize(configuration, current_version, include_ignored: false) ⇒ Semverve::VersionCodeReferences
constructor
Initializes code version literal scanning.
Constructor Details
#initialize(configuration, current_version, include_ignored: false) ⇒ Semverve::VersionCodeReferences
Initializes code version literal scanning.
102 103 104 105 106 |
# File 'lib/semverve/version_code_references.rb', line 102 def initialize(configuration, current_version, include_ignored: false) @configuration = configuration @current_version = current_version @include_ignored = include_ignored end |
Instance Method Details
#findings ⇒ Array<Semverve::VersionCodeReferences::Finding>
Code version literal findings in configured files.
112 113 114 |
# File 'lib/semverve/version_code_references.rb', line 112 def findings files.flat_map { |path| findings_for_file(path) } end |
#fix ⇒ Semverve::VersionCodeReferences::FixResult
Replaces found code version literals with the current version.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/semverve/version_code_references.rb', line 120 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 |