diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2016-04-18 21:36:21 -0500 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2016-04-18 21:36:21 -0500 |
commit | d7879943aabf6e2a2e48060b594d765e0b4f1c3a (patch) | |
tree | f4517a475566a9e52d4dcb7f52e291af20b779c9 | |
parent | 12d7fe0a63f04bcc9c351535aac2462765d984df (diff) | |
download | bundler-seg-generically-preserve-new-attributes.tar.gz |
[LockfileParser] Rename attribute to sectionseg-generically-preserve-new-attributes
-rw-r--r-- | lib/bundler/cli/check.rb | 2 | ||||
-rw-r--r-- | lib/bundler/definition.rb | 18 | ||||
-rw-r--r-- | lib/bundler/environment.rb | 2 | ||||
-rw-r--r-- | lib/bundler/lockfile_parser.rb | 16 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 2 | ||||
-rw-r--r-- | spec/bundler/lockfile_parser_spec.rb | 12 |
6 files changed, 26 insertions, 26 deletions
diff --git a/lib/bundler/cli/check.rb b/lib/bundler/cli/check.rb index 238cd9bd5e..738d40b622 100644 --- a/lib/bundler/cli/check.rb +++ b/lib/bundler/cli/check.rb @@ -32,7 +32,7 @@ module Bundler Bundler.ui.error "This bundle has been frozen, but there is no #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} present" exit 1 else - Bundler.load.lock(:preserve_new_attributes => true) unless options[:"dry-run"] + Bundler.load.lock(:preserve_unknown_sections => true) unless options[:"dry-run"] Bundler.ui.info "The Gemfile's dependencies are satisfied" end end diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 7607a472d7..c11dc2428c 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -247,7 +247,7 @@ module Bundler dependencies.map(&:groups).flatten.uniq end - def lock(file, preserve_new_attributes = false) + def lock(file, preserve_unknown_sections = false) contents = to_lock # Convert to \r\n if the existing lock has them @@ -264,8 +264,8 @@ module Bundler end end - preserve_new_attributes ||= !updating_major && (Bundler.settings[:frozen] || !@unlocking) - return if lockfiles_equal?(@lockfile_contents, contents, preserve_new_attributes) + preserve_unknown_sections ||= !updating_major && (Bundler.settings[:frozen] || !@unlocking) + return if lockfiles_equal?(@lockfile_contents, contents, preserve_unknown_sections) if Bundler.settings[:frozen] Bundler.ui.error "Cannot write a changed lockfile while frozen." @@ -678,12 +678,12 @@ module Bundler groups - Bundler.settings.without - @optional_groups + Bundler.settings.with end - def lockfiles_equal?(current, proposed, preserve_new_attributes) - if preserve_new_attributes - attributes_to_ignore = LockfileParser.attributes_to_ignore(@locked_bundler_version) - attributes_to_ignore += LockfileParser.unknown_attributes_in_lockfile(current) - attributes_to_ignore += LockfileParser::ENVIRONMENT_VERSION_ATTRIBUTES - pattern = /#{Regexp.union(attributes_to_ignore)}\n(\s{2,}.*\n)+/ + def lockfiles_equal?(current, proposed, preserve_unknown_sections) + if preserve_unknown_sections + sections_to_ignore = LockfileParser.sections_to_ignore(@locked_bundler_version) + sections_to_ignore += LockfileParser.unknown_sections_in_lockfile(current) + sections_to_ignore += LockfileParser::ENVIRONMENT_VERSION_SECTIONS + pattern = /#{Regexp.union(sections_to_ignore)}\n(\s{2,}.*\n)+/ whitespace_cleanup = /\n{2,}/ current = current.gsub(pattern, "\n").gsub(whitespace_cleanup, "\n\n").strip proposed = proposed.gsub(pattern, "\n").gsub(whitespace_cleanup, "\n\n").strip diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb index 912231409c..b12a146a77 100644 --- a/lib/bundler/environment.rb +++ b/lib/bundler/environment.rb @@ -32,7 +32,7 @@ module Bundler end def lock(opts = {}) - @definition.lock(Bundler.default_lockfile, opts[:preserve_new_attributes]) + @definition.lock(Bundler.default_lockfile, opts[:preserve_unknown_sections]) end def update(*gems) diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index 3025513f2d..e0c6dd1c38 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -26,29 +26,29 @@ module Bundler OPTIONS = /^ ([a-z]+): (.*)$/i SOURCE = [GIT, GEM, PATH].freeze - ATTRIBUTES_BY_VERSION_INTRODUCED = { + SECTIONS_BY_VERSION_INTRODUCED = { Gem::Version.create("1.0") => [DEPENDENCIES, PLATFORMS, GIT, GEM, PATH].freeze, Gem::Version.create("1.10") => [BUNDLED].freeze, Gem::Version.create("1.12") => [RUBY].freeze, }.freeze - ALL_KNOWN_ATTRIBUTES = ATTRIBUTES_BY_VERSION_INTRODUCED.values.flatten.freeze + KNOWN_SECTIONS = SECTIONS_BY_VERSION_INTRODUCED.values.flatten.freeze - ENVIRONMENT_VERSION_ATTRIBUTES = [BUNDLED, RUBY].freeze + ENVIRONMENT_VERSION_SECTIONS = [BUNDLED, RUBY].freeze - def self.attributes_in_lockfile(lockfile_contents) + def self.sections_in_lockfile(lockfile_contents) lockfile_contents.scan(/^\w[\w ]*$/).uniq end - def self.unknown_attributes_in_lockfile(lockfile_contents) - attributes_in_lockfile(lockfile_contents) - ALL_KNOWN_ATTRIBUTES + def self.unknown_sections_in_lockfile(lockfile_contents) + sections_in_lockfile(lockfile_contents) - KNOWN_SECTIONS end - def self.attributes_to_ignore(base_version = nil) + def self.sections_to_ignore(base_version = nil) base_version &&= base_version.release base_version ||= Gem::Version.create("1.0") attributes = [] - ATTRIBUTES_BY_VERSION_INTRODUCED.each do |version, introduced| + SECTIONS_BY_VERSION_INTRODUCED.each do |version, introduced| next if version <= base_version attributes += introduced end diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index a36441ef6e..c2f29a749f 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -52,7 +52,7 @@ module Bundler setup_manpath - lock(:preserve_new_attributes => true) + lock(:preserve_unknown_sections => true) self end diff --git a/spec/bundler/lockfile_parser_spec.rb b/spec/bundler/lockfile_parser_spec.rb index 44772c8b2a..d9bb32b4de 100644 --- a/spec/bundler/lockfile_parser_spec.rb +++ b/spec/bundler/lockfile_parser_spec.rb @@ -29,16 +29,16 @@ describe Bundler::LockfileParser do 1.12.0.rc.2 L - describe ".attributes_in_lockfile" do + describe ".sections_in_lockfile" do it "returns the attributes" do - attributes = described_class.attributes_in_lockfile(lockfile_contents) + attributes = described_class.sections_in_lockfile(lockfile_contents) expect(attributes).to contain_exactly( "BUNDLED WITH", "DEPENDENCIES", "GEM", "GIT", "PLATFORMS", "RUBY VERSION" ) end end - describe ".unknown_attributes_in_lockfile" do + describe ".unknown_sections_in_lockfile" do let(:lockfile_contents) { strip_whitespace(<<-L) } UNKNOWN ATTR @@ -47,13 +47,13 @@ describe Bundler::LockfileParser do L it "returns the unknown attributes" do - attributes = described_class.unknown_attributes_in_lockfile(lockfile_contents) + attributes = described_class.unknown_sections_in_lockfile(lockfile_contents) expect(attributes).to contain_exactly("UNKNOWN ATTR", "UNKNOWN ATTR 2") end end - describe ".attributes_to_ignore" do - subject { described_class.attributes_to_ignore(base_version) } + describe ".sections_to_ignore" do + subject { described_class.sections_to_ignore(base_version) } context "with a nil base version" do let(:base_version) { nil } |