summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-03-31 13:06:25 -0500
committerSamuel Giddins <segiddins@segiddins.me>2017-04-03 20:57:19 -0500
commitc91e77cab2d29f3e0ecb721430ee93c7c86f0859 (patch)
tree4088b038593d1e85cb2ca914e2f6296a06cdd726
parent9d18ac9c83f2922a3833796b5a98872af86fbf7a (diff)
downloadbundler-c91e77cab2d29f3e0ecb721430ee93c7c86f0859.tar.gz
[LockfileParser] Use a single name-version regexp
-rw-r--r--lib/bundler/lockfile_parser.rb66
1 files changed, 33 insertions, 33 deletions
diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb
index 8d89b8b4a3..344f3a58ae 100644
--- a/lib/bundler/lockfile_parser.rb
+++ b/lib/bundler/lockfile_parser.rb
@@ -171,43 +171,45 @@ module Bundler
end
end
- NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
- NAME_VERSION_2 = /^ {2}#{NAME_VERSION}(!)?$/
- NAME_VERSION_4 = /^ {4}#{NAME_VERSION}$/
- NAME_VERSION_6 = /^ {6}#{NAME_VERSION}$/
+ NAME_VERSION = /^( {2}| {4}| {6})(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?(!)?$/
def parse_dependency(line)
- if line =~ NAME_VERSION_2
- name = $1
- version = $2
- pinned = $4
- version = version.split(",").map(&:strip) if version
-
- dep = Bundler::Dependency.new(name, version)
-
- if pinned && dep.name != "bundler"
- spec = @specs.find {|_, v| v.name == dep.name }
- dep.source = spec.last.source if spec
-
- # Path sources need to know what the default name / version
- # to use in the case that there are no gemspecs present. A fake
- # gemspec is created based on the version set on the dependency
- # TODO: Use the version from the spec instead of from the dependency
- if version && version.size == 1 && version.first =~ /^\s*= (.+)\s*$/ && dep.source.is_a?(Bundler::Source::Path)
- dep.source.name = name
- dep.source.version = $1
- end
+ return unless line =~ NAME_VERSION
+ spaces = $1
+ return unless spaces.size == 2
+ name = $2
+ version = $3
+ pinned = $5
+
+ version = version.split(",").map(&:strip) if version
+
+ dep = Bundler::Dependency.new(name, version)
+
+ if pinned && dep.name != "bundler"
+ spec = @specs.find {|_, v| v.name == dep.name }
+ dep.source = spec.last.source if spec
+
+ # Path sources need to know what the default name / version
+ # to use in the case that there are no gemspecs present. A fake
+ # gemspec is created based on the version set on the dependency
+ # TODO: Use the version from the spec instead of from the dependency
+ if version && version.size == 1 && version.first =~ /^\s*= (.+)\s*$/ && dep.source.is_a?(Bundler::Source::Path)
+ dep.source.name = name
+ dep.source.version = $1
end
-
- @dependencies[dep.name] = dep
end
+
+ @dependencies[dep.name] = dep
end
def parse_spec(line)
- if line =~ NAME_VERSION_4
- name = $1
- version = $2
- platform = $3
+ return unless line =~ NAME_VERSION
+ spaces = $1
+ name = $2
+ version = $3
+ platform = $4
+
+ if spaces.size == 4
version = Gem::Version.new(version)
platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY
@current_spec = LazySpecification.new(name, version, platform)
@@ -216,9 +218,7 @@ module Bundler
# Avoid introducing multiple copies of the same spec (caused by
# duplicate GIT sections)
@specs[@current_spec.identifier] ||= @current_spec
- elsif line =~ NAME_VERSION_6
- name = $1
- version = $2
+ elsif spaces.size == 6
version = version.split(",").map(&:strip) if version
dep = Gem::Dependency.new(name, version)
@current_spec.dependencies << dep