summaryrefslogtreecommitdiff
path: root/lib/bundler/dsl.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bundler/dsl.rb')
-rw-r--r--lib/bundler/dsl.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
new file mode 100644
index 0000000000..a8b529c8a0
--- /dev/null
+++ b/lib/bundler/dsl.rb
@@ -0,0 +1,48 @@
+module Bundler
+ class DslError < StandardError; end
+
+ class Dsl
+ def self.evaluate(gemfile)
+ builder = new
+ builder.instance_eval(File.read(gemfile.to_s), gemfile.to_s, 1)
+ builder.to_definition
+ end
+
+ def initialize
+ @sources = [] # Gem.sources.map { |s| Source::Rubygems.new(:uri => s) }
+ @dependencies = []
+ @git = nil
+ @git_sources = {}
+ end
+
+ def gem(name, *args)
+ options = Hash === args.last ? args.pop : {}
+ version = args.last || ">= 0"
+
+ @dependencies << Dependency.new(name, version, options)
+ end
+
+ def source(source)
+ source = case source
+ when :gemcutter, :rubygems, :rubyforge then Source::Rubygems.new(:uri => "http://gemcutter.org")
+ when String then Source::Rubygems.new(:uri => source)
+ else source
+ end
+
+ @sources << source
+ end
+
+ def path(path, options = {})
+ source Source::Path.new(options.merge(:path => path))
+ end
+
+ def git(uri, options = {})
+ source Source::Git.new(options.merge(:uri => uri))
+ end
+
+ def to_definition
+ Definition.new(@dependencies, @sources)
+ end
+
+ end
+end \ No newline at end of file