Class: Bundler::LockfileParser
- Inherits:
-
Object
- Object
- Bundler::LockfileParser
- Defined in:
- lib/bundler/lockfile_parser.rb
Constant Summary collapse
- BUNDLED =
"BUNDLED WITH".freeze
- DEPENDENCIES =
"DEPENDENCIES".freeze
- PLATFORMS =
"PLATFORMS".freeze
- RUBY =
"RUBY VERSION".freeze
- GIT =
"GIT".freeze
- GEM =
"GEM".freeze
- PATH =
"PATH".freeze
- SPECS =
" specs:".freeze
- OPTIONS =
/^ ([a-z]+): (.*)$/i
- SOURCE =
[GIT, GEM, PATH].freeze
- 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
- KNOWN_SECTIONS =
SECTIONS_BY_VERSION_INTRODUCED.values.flatten.freeze
- ENVIRONMENT_VERSION_SECTIONS =
[BUNDLED, RUBY].freeze
Instance Attribute Summary collapse
-
#bundler_version ⇒ Object
readonly
Returns the value of attribute bundler_version.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#platforms ⇒ Object
readonly
Returns the value of attribute platforms.
-
#ruby_version ⇒ Object
readonly
Returns the value of attribute ruby_version.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
-
#specs ⇒ Object
readonly
Returns the value of attribute specs.
Class Method Summary collapse
- .sections_in_lockfile(lockfile_contents) ⇒ Object
- .sections_to_ignore(base_version = nil) ⇒ Object
- .unknown_sections_in_lockfile(lockfile_contents) ⇒ Object
Instance Method Summary collapse
-
#initialize(lockfile) ⇒ LockfileParser
constructor
A new instance of LockfileParser.
- #warn_for_outdated_bundler_version ⇒ Object
Constructor Details
#initialize(lockfile) ⇒ LockfileParser
Returns a new instance of LockfileParser.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/bundler/lockfile_parser.rb', line 58 def initialize(lockfile) @platforms = [] @sources = [] @dependencies = [] @state = nil @specs = {} @rubygems_aggregate = Source::Rubygems.new if lockfile.match(/<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|/) raise LockfileError, "Your #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} contains merge conflicts.\n" \ "Run `git checkout HEAD -- #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}` 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 == RUBY @state = :ruby 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 #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}` " \ "and then `bundle install` to generate a new lockfile." end |
Instance Attribute Details
#bundler_version ⇒ Object (readonly)
Returns the value of attribute bundler_version.
16 17 18 |
# File 'lib/bundler/lockfile_parser.rb', line 16 def bundler_version @bundler_version end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
16 17 18 |
# File 'lib/bundler/lockfile_parser.rb', line 16 def dependencies @dependencies end |
#platforms ⇒ Object (readonly)
Returns the value of attribute platforms.
16 17 18 |
# File 'lib/bundler/lockfile_parser.rb', line 16 def platforms @platforms end |
#ruby_version ⇒ Object (readonly)
Returns the value of attribute ruby_version.
16 17 18 |
# File 'lib/bundler/lockfile_parser.rb', line 16 def ruby_version @ruby_version end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
16 17 18 |
# File 'lib/bundler/lockfile_parser.rb', line 16 def sources @sources end |
#specs ⇒ Object (readonly)
Returns the value of attribute specs.
16 17 18 |
# File 'lib/bundler/lockfile_parser.rb', line 16 def specs @specs end |
Class Method Details
.sections_in_lockfile(lockfile_contents) ⇒ Object
39 40 41 |
# File 'lib/bundler/lockfile_parser.rb', line 39 def self.sections_in_lockfile(lockfile_contents) lockfile_contents.scan(/^\w[\w ]*$/).uniq end |
.sections_to_ignore(base_version = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bundler/lockfile_parser.rb', line 47 def self.sections_to_ignore(base_version = nil) base_version &&= base_version.release base_version ||= Gem::Version.create("1.0") attributes = [] SECTIONS_BY_VERSION_INTRODUCED.each do |version, introduced| next if version <= base_version attributes += introduced end attributes end |
.unknown_sections_in_lockfile(lockfile_contents) ⇒ Object
43 44 45 |
# File 'lib/bundler/lockfile_parser.rb', line 43 def self.unknown_sections_in_lockfile(lockfile_contents) sections_in_lockfile(lockfile_contents) - KNOWN_SECTIONS end |
Instance Method Details
#warn_for_outdated_bundler_version ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/bundler/lockfile_parser.rb', line 99 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 |