aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bundler/lockfile_parser.rb
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-04-20 17:51:12 -0700
committerCarlhuda <carlhuda@engineyard.com>2010-04-20 17:51:12 -0700
commitba579f4a3e525fdd78d89531291450b26a009b07 (patch)
treecd0a51cbbfb2bb6038535d52c2702fb5e60845fa /lib/bundler/lockfile_parser.rb
parent4bfff00e3bfc24c92c2a4e24ed08ad4e40942db2 (diff)
downloadbundler-ba579f4a3e525fdd78d89531291450b26a009b07.tar.gz
Remove temporary flex stuff
Diffstat (limited to 'lib/bundler/lockfile_parser.rb')
-rw-r--r--lib/bundler/lockfile_parser.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb
new file mode 100644
index 00000000..572791d8
--- /dev/null
+++ b/lib/bundler/lockfile_parser.rb
@@ -0,0 +1,79 @@
+require "strscan"
+
+module Bundler
+ class LockfileParser
+ attr_reader :sources, :dependencies, :specs
+
+ # Do stuff
+ def initialize(lockfile)
+ @sources = []
+ @dependencies = []
+ @specs = []
+
+ lockfile.split(/\n+/).each do |line|
+ case line
+ when "sources:"
+ @state = :source
+ when "dependencies:"
+ @state = :dependencies
+ when "specs:"
+ @state = :specs
+ else
+ send("parse_#{@state}", line)
+ end
+ end
+ end
+
+ private
+
+ TYPES = {
+ "git" => Bundler::Source::Git,
+ "gem" => Bundler::Source::Rubygems,
+ "path" => Bundler::Source::Path
+ }
+
+ def parse_source(line)
+ @sources << parse_source_line(line)
+ end
+
+ def parse_source_line(line)
+ type, source, option_line = line.match(/^\s+(\w+): ([^\s]*?)(?: (.*))?$/).captures
+ options = extract_options(option_line)
+ TYPES[type].from_lock(source, options)
+ end
+
+ NAME_VERSION = '(?! )(.*?)(?: \((.*)\))?:?'
+
+ def parse_dependencies(line)
+ if line =~ %r{^ {2}#{NAME_VERSION}$}
+ name, version = $1, $2
+
+ @current = Bundler::Dependency.new(name, version)
+ @dependencies << @current
+ else
+ @current.source = parse_source_line(line)
+ end
+ end
+
+ def parse_specs(line)
+ if line =~ %r{^ {2}#{NAME_VERSION}$}
+ @current = LazySpecification.new($1, $2)
+ @specs << @current
+ else
+ line =~ %r{^ {4}#{NAME_VERSION}$}
+ @current.dependencies << Gem::Dependency.new($1, $2)
+ end
+ end
+
+ def extract_options(line)
+ options = {}
+ return options unless line
+
+ line.scan(/(\w+):"((?:|.*?[^\\])(?:\\\\)*)" ?/) do |k,v|
+ options[k] = v
+ end
+
+ options
+ end
+ end
+end \ No newline at end of file