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
- 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) ⇒ Semverve::VersionCodeReferences
constructor
Initializes code version literal scanning.
Constructor Details
#initialize(configuration, current_version) ⇒ Semverve::VersionCodeReferences
Initializes code version literal scanning.
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
#findings ⇒ Array<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 |
#fix ⇒ Semverve::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 |