Class: Bundler::LockfileParser

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/lockfile_parser.rb

Constant Summary

BUNDLED =
"BUNDLED WITH"
DEPENDENCIES =
"DEPENDENCIES"
PLATFORMS =
"PLATFORMS"
GIT =
"GIT"
GEM =
"GEM"
PATH =
"PATH"
SPECS =
"  specs:"
OPTIONS =
/^  ([a-z]+): (.*)$/i
SOURCE =
[GIT, GEM, PATH]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lockfile) ⇒ LockfileParser

Returns a new instance of LockfileParser



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bundler/lockfile_parser.rb', line 27

def initialize(lockfile)
  @platforms    = []
  @sources      = []
  @dependencies = []
  @state        = nil
  @specs        = {}

  @rubygems_aggregate = Source::Rubygems.new

  if lockfile.match(/<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|/)
    raise LockfileError, "Your Gemfile.lock contains merge conflicts.\n" \
      "Run `git checkout HEAD -- Gemfile.lock` first to get a clean lock."
  end

  lockfile.split(/(?:\r?\n)+/).each do |line|
    if SOURCE.include?(line)
      @state = :source
      parse_source(line)
    elsif line == DEPENDENCIES
      @state = :dependency
    elsif line == PLATFORMS
      @state = :platform
    elsif line == BUNDLED
      @state = :bundled_with
    elsif line =~ /^[^\s]/
      @state = nil
    elsif @state
      send("parse_#{@state}", line)
    end
  end
  @sources << @rubygems_aggregate
  @specs = @specs.values
  warn_for_outdated_bundler_version
rescue ArgumentError => e
  Bundler.ui.debug(e)
  raise LockfileError, "Your lockfile is unreadable. Run `rm Gemfile.lock` " \
    "and then `bundle install` to generate a new lockfile."
end

Instance Attribute Details

#bundler_versionObject (readonly)

Returns the value of attribute bundler_version



15
16
17
# File 'lib/bundler/lockfile_parser.rb', line 15

def bundler_version
  @bundler_version
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies



15
16
17
# File 'lib/bundler/lockfile_parser.rb', line 15

def dependencies
  @dependencies
end

#platformsObject (readonly)

Returns the value of attribute platforms



15
16
17
# File 'lib/bundler/lockfile_parser.rb', line 15

def platforms
  @platforms
end

#sourcesObject (readonly)

Returns the value of attribute sources



15
16
17
# File 'lib/bundler/lockfile_parser.rb', line 15

def sources
  @sources
end

#specsObject (readonly)

Returns the value of attribute specs



15
16
17
# File 'lib/bundler/lockfile_parser.rb', line 15

def specs
  @specs
end

Instance Method Details

#warn_for_outdated_bundler_versionObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bundler/lockfile_parser.rb', line 66

def warn_for_outdated_bundler_version
  return unless bundler_version
  prerelease_text = bundler_version.prerelease? ? " --pre" : ""
  current_version = Gem::Version.create(Bundler::VERSION)
  case current_version.segments.first <=> bundler_version.segments.first
  when -1
    raise LockfileError, "You must use Bundler #{bundler_version.segments.first} or greater with this lockfile."
  when 0
    if current_version < bundler_version
      Bundler.ui.warn "Warning: the running version of Bundler is older " \
           "than the version that created the lockfile. We suggest you " \
           "upgrade to the latest version of Bundler by running `gem " \
           "install bundler#{prerelease_text}`.\n"
    end
  end
end