Permalink
Browse files

Accept :all (default) to make all gems local. All ENV variables can b…

…e arrays separated by ';'. Updated README
  • Loading branch information...
1 parent ff7b4bd commit 1e60d65a5df5b1a105d9fbfbbaffec670ac2aa60 @ndbroadbent committed May 11, 2012
Showing with 42 additions and 16 deletions.
  1. +4 −1 README.md
  2. +37 −14 lib/bundler/local_development.rb
  3. +1 −1 lib/bundler_local_development/version.rb
View
@@ -26,17 +26,20 @@ And then execute:
* Call `Bundler.development_gems = [...]` in your Gemfile, to configure
your default set of local gems.
You can provide regular expressions or strings to match gem names.
-* Set the `$DEV_GEMS` environment variable to add extra gems to this list (comma separated list of gem names).
+* Set the `$DEV_GEMS` environment variable to add extra gems to this list (semicolon separated list of gem names).
If the `$GEM_DEV` environment variable is unset, this gem will have no effect.
If the `$GEM_DEV` environment variable is set:
* Bundler will search for local gems in the
path specified by `$GEM_DEV_DIR`. (The default search path is `$HOME/code/gems`, if `$GEM_DEV_DIR` is unset.)
+You can specify multiple directories by separating paths with a semicolon, e.g.
+`$HOME/code/gems;$HOME/code/more_gems`
* If a local copy of the gem is found, it will add the `:path => <path>`
option to the `gem` command.
+It will also scan the local gem's gemspec and process any runtime dependencies.
* `Gemfile.lock` will **NOT** be updated if this gem is activated.
@@ -11,37 +11,60 @@
module Bundler
class << self
def development_gems=(search_strings)
- @@development_gems = search_strings
+ @@development_gems = [search_strings].flatten
end
def development_gems
- (@@development_gems ||= []) +
- ENV['DEV_GEMS'].to_s.split(',').map(&:strip).select{|s| s != "" }
+ # If $DEV_GEMS is provided, append to @@development_gems
+ if ENV['DEV_GEMS']
+ (@@development_gems ||= []) +
+ ENV['DEV_GEMS'].to_s.split(';').map(&:strip).select{|s| s != "" }
+ # Otherwise, default is to make all gems local
+ else
+ @@development_gems ||= [:all]
+ end
end
end
class Dsl
alias :gem_without_development :gem
def gem_with_development(name, *args)
- if ENV['GEM_DEV'] && Bundler.development_gems.any?{ |s| name[s] }
- gem_dev_dir = ENV['GEM_DEV_DIR'] || "#{`echo $HOME`.strip}/code/gems"
- path = File.join(gem_dev_dir, name)
- if File.exist?(path)
- # Check each local gem's gemspec to see if any dependencies need to be made local
- gemspec_path = File.join(gem_dev_dir, name, "#{name}.gemspec")
- process_gemspec_dependencies(gemspec_path, gem_dev_dir) if File.exist?(gemspec_path)
- return gem_without_development name, :path => path
+ if ENV['GEM_DEV']
+ if Bundler.development_gems == [:all] || Bundler.development_gems.any?{ |s| name[s] }
+ gem_development_dirs.each do |dir|
+ path = File.join(dir, name)
+ if File.exist?(path)
+ # Check each local gem's gemspec to see if any dependencies need to be made local
+ gemspec_path = File.join(dir, name, "#{name}.gemspec")
+ process_gemspec_dependencies(gemspec_path) if File.exist?(gemspec_path)
+ return gem_without_development name, :path => path
+ end
+ end
end
end
gem_without_development(name, *args)
end
alias :gem :gem_with_development
private
- def process_gemspec_dependencies(gemspec_path, gem_dev_dir)
+ # Returns local gem dirs from ENV or default
+ def gem_development_dirs
+ @gem_development_dirs ||= if ENV['GEM_DEV_DIR']
+ ENV['GEM_DEV_DIR'].split(';')
+ else
+ ["#{`echo $HOME`.strip}/code/gems"]
+ end
+ end
+
+ def process_gemspec_dependencies(gemspec_path)
spec = Bundler.load_gemspec(gemspec_path)
spec.runtime_dependencies.each do |dep|
- path = File.join(gem_dev_dir, dep.name)
- gem_without_development(dep.name, :path => path) if File.exist?(path)
+ gem_development_dirs.each do |dir|
+ path = File.join(dir, dep.name)
+ if File.exist?(path)
+ gem_without_development(dep.name, :path => path)
+ break # Process next dependency
+ end
+ end
end
end
end
@@ -1,3 +1,3 @@
module BundlerLocalDevelopment
- VERSION = "0.2.0"
+ VERSION = "0.3.0"
end

0 comments on commit 1e60d65

Please sign in to comment.