lib/keep_up/bundle.rb in keep_up-0.10.1 vs lib/keep_up/bundle.rb in keep_up-0.10.2

- old
+ new

@@ -1,18 +1,19 @@ # frozen_string_literal: true require_relative "gemfile_filter" require_relative "gemspec_filter" require_relative "dependency" +require_relative "dependency_set" module KeepUp # A Gemfile with its current set of locked dependencies. class Bundle OUTDATED_MATCHER = /([^ ]*) \(newest ([^,]*), installed ([^,]*)(?:, requested (.*))?\)/.freeze UPDATE_MATCHER = - /(?:Using|Installing|Fetching) ([^ ]*) ([^ ]*)(?: \(was (.*))?\)/.freeze + /(?:Using|Installing|Fetching) ([^ ]*) ([^ ]*)(?: \(was (.*)\))?/.freeze def initialize(runner:, local:) @runner = runner @local = local end @@ -26,37 +27,41 @@ build_dependency(name, newest, version, requirement) end end end + def dependency_set + @dependency_set ||= DependencySet.new(dependencies) + end + def check? _, status = @runner.run2 "bundle check" status == 0 end def update_gemfile_contents(update) - update = find_specification_update(dependencies, update) + update = dependency_set.find_specification_update(update) return unless update - update if update_specification_contents(update, "Gemfile", GemfileFilter) + update if GemfileFilter.apply_to_file("Gemfile", update) end def update_gemspec_contents(update) return unless gemspec_name - update = find_specification_update(dependencies, update) + update = dependency_set.find_specification_update(update) return unless update - update if update_specification_contents(update, gemspec_name, GemspecFilter) + update if GemspecFilter.apply_to_file(gemspec_name, update) end # Update lockfile and return resulting spec, or false in case of failure - def update_lockfile(update) + def update_lockfile(update, old_version) update_name = update.name command = "bundle update#{" --local" if @local} --conservative #{update_name}" lines = run_filtered command, UPDATE_MATCHER - lines.each do |name, version, old_version| + lines.each do |name, version, _old_version| next unless name == update_name && old_version current = Gem::Specification.new(name, old_version) result = Gem::Specification.new(name, version) return result if result.version > current.version @@ -99,27 +104,9 @@ def fetch_gemspec_dependency_requirements(name) dep = gemspec_dependencies.find { |it| it.name == name } return unless dep dep.requirements_list - end - - def find_specification_update(current_dependencies, update) - current_dependency = current_dependencies.find { |it| it.name == update.name } - return if !current_dependency || current_dependency.matches_spec?(update) - - current_dependency.generalize_specification(update) - end - - def update_specification_contents(update, file, filter) - contents = File.read(file) - updated_contents = filter.apply(contents, update) - if contents == updated_contents - false - else - File.write file, updated_contents - true - end end def gemspec_name @gemspec_name ||= Dir.glob("*.gemspec").first end