summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-01-28 16:24:44 -0800
committerCarlhuda <carlhuda@engineyard.com>2010-01-28 16:24:44 -0800
commit8637b672564c5f48681d37a41fb5b6988ed524f8 (patch)
treeacf18c565a0caa3336e1c2eed68733ad76a639d3 /lib
parentacab5a322549a370c39e4f36149aba81f519c389 (diff)
downloadbundler-8637b672564c5f48681d37a41fb5b6988ed524f8.tar.gz
Implementing groups and install --without
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler.rb5
-rw-r--r--lib/bundler/cli.rb3
-rw-r--r--lib/bundler/dependency.rb4
-rw-r--r--lib/bundler/environment.rb11
-rw-r--r--lib/bundler/installer.rb30
-rw-r--r--lib/bundler/rubygems.rb8
6 files changed, 48 insertions, 13 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 2a53e2ee6b..8e47d6f582 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -31,8 +31,9 @@ module Bundler
@ui = ui
end
- def self.setup(gemfile = default_gemfile)
- load(gemfile).setup
+ def self.setup(*groups)
+ gemfile = default_gemfile
+ load(gemfile).setup(*groups)
end
def self.load(gemfile = default_gemfile)
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index f0c144d06e..d700caa0ad 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -49,8 +49,9 @@ module Bundler
end
desc "install", "Install the current environment to the system"
+ method_option :without, :type => :array, :banner => "Exclude gems thar are part of the specified named group"
def install
- Installer.install(Bundler.root, Bundler.definition)
+ Installer.install(Bundler.root, Bundler.definition, options)
end
desc "lock", "Locks a resolve"
diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb
index 21ebd82843..253efafd57 100644
--- a/lib/bundler/dependency.rb
+++ b/lib/bundler/dependency.rb
@@ -2,12 +2,12 @@ require 'rubygems/dependency'
module Bundler
class Dependency < Gem::Dependency
- attr_accessor :source, :group
+ attr_accessor :source
def initialize(name, version, options = {}, &blk)
super(name, version)
- @group = options[:group]
+ @group = options["group"]
end
end
end \ No newline at end of file
diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb
index ba8f9273f4..b5d52d9f99 100644
--- a/lib/bundler/environment.rb
+++ b/lib/bundler/environment.rb
@@ -7,15 +7,15 @@ module Bundler
@definition = definition
end
- def setup
+ def setup(*groups)
# Has to happen first
cripple_rubygems
# Activate the specs
- specs.each do |spec|
+ specs_for(*groups).each do |spec|
Gem.loaded_specs[spec.name] = spec
+ $LOAD_PATH.unshift(*spec.load_paths)
end
- $LOAD_PATH.unshift(*load_paths)
self
end
@@ -29,6 +29,11 @@ module Bundler
write_rb_lock
end
+ def specs_for(*groups)
+ return specs if groups.empty?
+ specs.select { |s| (s.groups & groups).any? }
+ end
+
def specs
@specs ||= Resolver.resolve(@definition.actual_dependencies, index)
end
diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb
index 22db01b44e..9ee104d234 100644
--- a/lib/bundler/installer.rb
+++ b/lib/bundler/installer.rb
@@ -2,8 +2,8 @@ require 'rubygems/dependency_installer'
module Bundler
class Installer
- def self.install(root, definition)
- new(root, definition).run
+ def self.install(root, definition, options)
+ new(root, definition).run(options)
end
attr_reader :root
@@ -13,14 +13,17 @@ module Bundler
@definition = definition
end
- def run
+ def run(options)
if dependencies.empty?
Bundler.ui.warn "The Gemfile specifies no dependencies"
return
end
+ without = options[:without] ? options[:without].map {|w| w.to_sym } : []
+
specs.each do |spec|
next unless spec.source.respond_to?(:install)
+ next if (spec.groups & without).any?
spec.source.install(spec)
end
@@ -32,7 +35,7 @@ module Bundler
end
def specs
- @specs ||= resolve_locally || resolve_remotely
+ @specs ||= group_specs(resolve_locally || resolve_remotely)
end
private
@@ -62,8 +65,25 @@ module Bundler
specs
end
+ def group_specs(specs)
+ dependencies.each do |d|
+ spec = specs.find { |s| s.name == d.name }
+ group_spec(specs, spec, d.group)
+ end
+ specs
+ end
+
+ def group_spec(specs, spec, group)
+ spec.groups << group
+ spec.groups.uniq!
+ spec.dependencies.each do |d|
+ spec = specs.find { |s| s.name == d.name }
+ group_spec(specs, spec, group)
+ end
+ end
+
def unambiguous?(dep)
- dep.version_requirements.requirements.all? { |op,_| op == '=' }
+ dep.version_requirements.requirements.all? { |op,_| op == '=' }
end
def index
diff --git a/lib/bundler/rubygems.rb b/lib/bundler/rubygems.rb
index 498f9f85ae..55c9af23de 100644
--- a/lib/bundler/rubygems.rb
+++ b/lib/bundler/rubygems.rb
@@ -10,5 +10,13 @@ module Gem
def load_paths
require_paths.map {|p| File.join(full_gem_path, p) }
end
+
+ def groups
+ @groups ||= []
+ end
+ end
+
+ class Dependency
+ attr_accessor :group
end
end \ No newline at end of file