Parent

Class Index [+]

Quicksearch

Bundler::LockfileParser

Constants

TYPES
NAME_VERSION

Attributes

sources[R]
dependencies[R]
specs[R]
platforms[R]

Public Class Methods

new(lockfile) click to toggle source
    # File lib/bundler/lockfile_parser.rb, line 17
17:     def initialize(lockfile)
18:       @platforms    = []
19:       @sources      = []
20:       @dependencies = []
21:       @specs        = []
22:       @state        = :source
23: 
24:       lockfile.split(/(\r?\n)+/).each do |line|
25:         if line == "DEPENDENCIES"
26:           @state = :dependency
27:         elsif line == "PLATFORMS"
28:           @state = :platform
29:         else
30:           send("parse_#{@state}", line)
31:         end
32:       end
33:     end

Private Instance Methods

parse_dependency(line) click to toggle source
     # File lib/bundler/lockfile_parser.rb, line 77
 77:     def parse_dependency(line)
 78:       if line =~ %{^ {2}#{NAME_VERSION}(!)?$}
 79:         name, version, pinned = $1, $2, $4
 80:         version = version.split(",").map { |d| d.strip } if version
 81: 
 82:         dep = Bundler::Dependency.new(name, version)
 83: 
 84:         if pinned && dep.name != 'bundler'
 85:           spec = @specs.find { |s| s.name == dep.name }
 86:           dep.source = spec.source if spec
 87: 
 88:           # Path sources need to know what the default name / version
 89:           # to use in the case that there are no gemspecs present. A fake
 90:           # gemspec is created based on the version set on the dependency
 91:           # TODO: Use the version from the spec instead of from the dependency
 92:           if version && version.size == 1 && version.first =~ /^\s*= (.+)\s*$/ && dep.source.is_a?(Bundler::Source::Path)
 93:             dep.source.name    = name
 94:             dep.source.version = $1
 95:           end
 96:         end
 97: 
 98:         @dependencies << dep
 99:       end
100:     end
parse_platform(line) click to toggle source
     # File lib/bundler/lockfile_parser.rb, line 120
120:     def parse_platform(line)
121:       if line =~ /^  (.*)$/
122:         @platforms << Gem::Platform.new($1)
123:       end
124:     end
parse_source(line) click to toggle source
    # File lib/bundler/lockfile_parser.rb, line 43
43:     def parse_source(line)
44:       case line
45:       when "GIT", "GEM", "PATH"
46:         @current_source = nil
47:         @opts, @type = {}, line
48:       when "  specs:"
49:         @current_source = TYPES[@type].from_lock(@opts)
50: 
51:         # Strip out duplicate GIT sections
52:         if @sources.include?(@current_source) && @current_source.is_a?(Bundler::Source::Git)
53:           @current_source = @sources.find { |s| s == @current_source }
54:         end
55: 
56:         @sources << @current_source
57:       when /^  ([a-z]+): (.*)$/
58:         value = $2
59:         value = true if value == "true"
60:         value = false if value == "false"
61: 
62:         key = $1
63: 
64:         if @opts[key]
65:           @opts[key] = Array(@opts[key])
66:           @opts[key] << value
67:         else
68:           @opts[key] = value
69:         end
70:       else
71:         parse_spec(line)
72:       end
73:     end
parse_spec(line) click to toggle source
     # File lib/bundler/lockfile_parser.rb, line 102
102:     def parse_spec(line)
103:       if line =~ %{^ {4}#{NAME_VERSION}$}
104:         name, version = $1, Gem::Version.new($2)
105:         platform = $3 ? Gem::Platform.new($3) : Gem::Platform::RUBY
106:         @current_spec = LazySpecification.new(name, version, platform)
107:         @current_spec.source = @current_source
108: 
109:         # Avoid introducing multiple copies of the same spec (caused by
110:         # duplicate GIT sections)
111:         @specs << @current_spec unless @specs.include?(@current_spec)
112:       elsif line =~ %{^ {6}#{NAME_VERSION}$}
113:         name, version = $1, $2
114:         version = version.split(',').map { |d| d.strip } if version
115:         dep = Gem::Dependency.new(name, version)
116:         @current_spec.dependencies << dep
117:       end
118:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.