summaryrefslogtreecommitdiff
path: root/lib/bundler/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bundler/runtime')
-rw-r--r--lib/bundler/runtime/dependency.rb56
-rw-r--r--lib/bundler/runtime/dsl.rb44
2 files changed, 100 insertions, 0 deletions
diff --git a/lib/bundler/runtime/dependency.rb b/lib/bundler/runtime/dependency.rb
new file mode 100644
index 0000000000..75d15a27fa
--- /dev/null
+++ b/lib/bundler/runtime/dependency.rb
@@ -0,0 +1,56 @@
+module Bundler
+ class InvalidEnvironmentName < StandardError; end
+
+ class Dependency
+ attr_reader :name, :version, :require_as, :only, :except
+
+ def initialize(name, options = {}, &block)
+ options.each do |k, v|
+ options[k.to_s] = v
+ end
+
+ @name = name
+ @version = options["version"] || ">= 0"
+ @require_as = Array(options["require_as"] || name)
+ @only = Array(options["only"]).map {|e| e.to_s } if options["only"]
+ @except = Array(options["except"]).map {|e| e.to_s } if options["except"]
+ @block = block
+
+ if (@only && @only.include?("rubygems")) || (@except && @except.include?("rubygems"))
+ raise InvalidEnvironmentName, "'rubygems' is not a valid environment name"
+ end
+ end
+
+ def in?(environment)
+ environment = environment.to_s
+
+ return false unless !@only || @only.include?(environment)
+ return false if @except && @except.include?(environment)
+ true
+ end
+
+ def to_s
+ to_gem_dependency.to_s
+ end
+
+ def require(environment)
+ return unless in?(environment)
+
+ @require_as.each do |file|
+ super(file)
+ end
+
+ @block.call if @block
+ end
+
+ def to_gem_dependency
+ @gem_dep ||= Gem::Dependency.new(name, version)
+ end
+
+ def ==(o)
+ [name, version, require_as, only, except] ==
+ [o.name, o.version, o.require_as, o.only, o.except]
+ end
+
+ end
+end
diff --git a/lib/bundler/runtime/dsl.rb b/lib/bundler/runtime/dsl.rb
new file mode 100644
index 0000000000..436867b4db
--- /dev/null
+++ b/lib/bundler/runtime/dsl.rb
@@ -0,0 +1,44 @@
+module Bundler
+ class ManifestFileNotFound < StandardError; end
+
+ def self.require(environment = nil)
+ ManifestBuilder.run(@gemfile, environment || :default)
+ end
+
+ class ManifestBuilder
+ def self.run(gemfile, environment)
+ unless File.exist?(gemfile)
+ raise ManifestFileNotFound, "#{gemfile.inspect} does not exist"
+ end
+
+ builder = new(environment)
+ builder.instance_eval(File.read(gemfile))
+ builder
+ end
+
+ def initialize(environment)
+ @environment = environment
+ end
+
+ def bundle_path(*) ; end
+
+ def bin_path(*) ; end
+
+ def disable_rubygems(*) ; end
+
+ def disable_system_gems(*) ; end
+
+ def source(*) ; end
+
+ def clear_sources(*) ; end
+
+ def gem(name, *args, &blk)
+ options = args.last.is_a?(Hash) ? args.pop : {}
+ version = args.last
+
+ dep = Dependency.new(name, options.merge(:version => version), &blk)
+ dep.require(@environment)
+ dep
+ end
+ end
+end \ No newline at end of file