Skip to content
Browse files

First pass at lockfile parser

  • Loading branch information...
1 parent 50715c4 commit f779dee772f0e7a0c60ec537c4be739e1756e0cf Carlhuda committed Apr 20, 2010
Showing with 17 additions and 14 deletions.
  1. +1 −0 lib/bundler.rb
  2. +9 −6 lib/bundler/flex/lockfile_parser.rb
  3. +4 −8 lib/bundler/lazy_specification.rb
  4. +3 −0 spec/unit/parser_spec.rb
View
1 lib/bundler.rb
@@ -14,6 +14,7 @@ module Bundler
autoload :Flex, 'bundler/flex'
autoload :Index, 'bundler/index'
autoload :Installer, 'bundler/installer'
+ autoload :LazySpecification, 'bundler/lazy_specification'
autoload :RemoteSpecification, 'bundler/remote_specification'
autoload :Resolver, 'bundler/resolver'
autoload :Runtime, 'bundler/runtime'
View
15 lib/bundler/flex/lockfile_parser.rb
@@ -3,12 +3,13 @@
module Bundler
module Flex
class LockfileParser
- attr_reader :sources, :dependencies
+ attr_reader :sources, :dependencies, :specs
# Do stuff
def initialize(lockfile)
@sources = []
@dependencies = []
+ @specs = []
lockfile.split(/\n+/).each do |line|
case line
@@ -42,10 +43,10 @@ def parse_source_line(line)
TYPES[type].from_lock(source, options)
end
- NAME_VERSION = '([^\)]+)(?: \(.+\))?:?'
+ NAME_VERSION = '(.*?)(?: \((.*)\))?'
def parse_dependencies(line)
- if line =~ %r{^ #{NAME_VERSION}$}
+ if line =~ %r{^ {2}#{NAME_VERSION}$}
name, version = $1, $2
@current = Bundler::Dependency.new(name, version)
@@ -56,10 +57,12 @@ def parse_dependencies(line)
end
def parse_specs(line)
- if line =~ %r{^ #{NAME_VERSION}$}
- @current =
+ if line =~ %r{^ {2}#{NAME_VERSION}$}
+ @current = LazySpecification.new($1, $2)
+ @specs << @current
else
-
+ line =~ %r{^ {4}#{NAME_VERSION}$}
+ @current.dependencies << Gem::Dependency.new(name, version)
end
end
View
12 lib/bundler/lazy_specification.rb
@@ -2,17 +2,13 @@
require "rubygems/spec_fetcher"
module Bundler
- # Represents a lazily loaded gem specification, where the full specification
- # is on the source server in rubygems' "quick" index. The proxy object is to
- # be seeded with what we're given from the source's abbreviated index - the
- # full specification will only be fetched when necesary.
class LazySpecification
- attr_reader :name, :version
- attr_accessor :source
+ attr_reader :name, :version, :dependencies
def initialize(name, version)
- @name = name
- @version = version
+ @name = name
+ @version = version
+ @dependencies = []
end
end
end
View
3 spec/unit/parser_spec.rb
@@ -35,6 +35,9 @@ def locked
it "has rack listed as a specification" do
specs = locked.specs
specs.size.should == 1
+ spec = specs.first
+ spec.name.should == "rack"
+ spec.version.should == "1.0.0"
end
end
end

0 comments on commit f779dee

Please sign in to comment.
Something went wrong with that request. Please try again.