Permalink
Browse files

Some small refactoring

  • Loading branch information...
1 parent 57f363a commit 68d4ebe4ef71f1f46bd9160ad388933ded13776c @wycats wycats committed Oct 22, 2009
Showing with 40 additions and 28 deletions.
  1. +3 −3 bundler.gemspec
  2. +9 −4 lib/bundler/dsl.rb
  3. +13 −13 lib/bundler/environment.rb
  4. +15 −8 lib/bundler/repository.rb
View
@@ -2,15 +2,15 @@
Gem::Specification.new do |s|
s.name = %q{bundler}
- s.version = "0.6.0.pre"
+ s.version = "0.7.0.pre"
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
s.authors = ["Yehuda Katz", "Carl Lerche"]
- s.date = %q{2009-09-22}
+ s.date = %q{2009-10-21}
s.description = %q{An easy way to vendor gem dependencies}
s.email = ["wycats@gmail.com", "clerche@engineyard.com"]
s.extra_rdoc_files = ["README.markdown", "LICENSE"]
- s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/bundler", "lib/bundler/cli.rb", "lib/bundler/commands", "lib/bundler/commands/bundle_command.rb", "lib/bundler/commands/exec_command.rb", "lib/bundler/dependency.rb", "lib/bundler/dsl.rb", "lib/bundler/environment.rb", "lib/bundler/finder.rb", "lib/bundler/gem_bundle.rb", "lib/bundler/gem_ext.rb", "lib/bundler/remote_specification.rb", "lib/bundler/repository.rb", "lib/bundler/resolver.rb", "lib/bundler/runtime.rb", "lib/bundler/source.rb", "lib/bundler/templates", "lib/bundler/templates/app_script.erb", "lib/bundler/templates/environment.erb", "lib/bundler.rb", "lib/rubygems_plugin.rb"]
+ s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/bundler", "lib/bundler/cli.rb", "lib/bundler/commands", "lib/bundler/commands/bundle_command.rb", "lib/bundler/commands/exec_command.rb", "lib/bundler/dependency.rb", "lib/bundler/dsl.rb", "lib/bundler/environment.rb", "lib/bundler/finder.rb", "lib/bundler/gem_bundle.rb", "lib/bundler/gem_ext.rb", "lib/bundler/logger.rb", "lib/bundler/remote_specification.rb", "lib/bundler/repository.rb", "lib/bundler/resolver.rb", "lib/bundler/runtime.rb", "lib/bundler/source.rb", "lib/bundler/templates", "lib/bundler/templates/app_script.erb", "lib/bundler/templates/environment.erb", "lib/bundler.rb", "lib/rubygems_plugin.rb"]
s.homepage = %q{http://github.com/wycats/bundler}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.5}
View
@@ -2,6 +2,11 @@ module Bundler
class ManifestFileNotFound < StandardError; end
class Dsl
+ def self.evaluate(environment, file)
+ builder = new(environment)
+ builder.instance_eval(File.read(file), file)
+ end
+
def initialize(environment)
@environment = environment
@directory_sources = []
@@ -37,13 +42,13 @@ def source(source)
end
def only(*env)
- old, @only = @only, _combine_only(env.flatten)
+ old, @only = @only, _combine_only(env)
yield
@only = old
end
def except(*env)
- old, @except = @except, _combine_except(env.flatten)
+ old, @except = @except, _combine_except(env)
yield
@except = old
end
@@ -149,14 +154,14 @@ def _handle_git_option(name, version, options)
def _combine_only(only)
return @only unless only
- only = [only].flatten.compact.uniq.map { |o| o.to_s }
+ only = Array(only).compact.uniq.map { |o| o.to_s }
only &= @only if @only
only
end
def _combine_except(except)
return @except unless except
- except = [except].flatten.compact.uniq.map { |o| o.to_s }
+ except = Array(except).compact.uniq.map { |o| o.to_s }
except |= @except if @except
except
end
View
@@ -10,8 +10,8 @@ class Environment
attr_accessor :rubygems, :system_gems
attr_writer :gem_path, :bindir
- def self.load(gemfile = nil)
- gemfile = gemfile ? Pathname.new(gemfile).expand_path : default_manifest_file
+ def self.load(file = nil)
+ gemfile = Pathname.new(file || default_manifest_file).expand_path
unless gemfile.file?
raise ManifestFileNotFound, "Manifest file not found: #{gemfile.to_s.inspect}"
@@ -32,34 +32,30 @@ def self.default_manifest_file
raise DefaultManifestNotFound
end
- def initialize(filename) #, sources, dependencies, bindir, path, rubygems, system_gems)
+ def initialize(filename)
@filename = filename
- @default_sources = [GemSource.new(:uri => "http://gems.rubyforge.org"), SystemGemSource.instance]
+ @default_sources = default_sources
@sources = []
@priority_sources = []
@dependencies = []
@rubygems = true
@system_gems = true
# Evaluate the Gemfile
- builder = Dsl.new(self)
- builder.instance_eval(File.read(filename), filename)
+ Dsl.evaluate(self, filename)
end
def install(options = {})
- update = options[:update]
- cached = options[:cached]
-
- no_bundle = dependencies.select { |dep| !dep.bundle }
+ no_bundle = dependencies.map { |dep| !dep.bundle && dep.name }.compact
repository.install(gem_dependencies, sources,
:rubygems => rubygems,
:system_gems => system_gems,
:manifest => filename,
- :update => update,
- :cached => cached,
+ :update => options[:update],
+ :cached => options[:cached],
:build_options => options[:build_options],
- :no_bundle => no_bundle.map { |dep| dep.name }
+ :no_bundle => no_bundle
)
Bundler.logger.info "Done."
end
@@ -149,6 +145,10 @@ def clear_sources
private
+ def default_sources
+ [GemSource.new(:uri => "http://gems.rubyforge.org"), SystemGemSource.instance]
+ end
+
def repository
@repository ||= Repository.new(gem_path, bindir)
end
View
@@ -25,15 +25,16 @@ def install(dependencies, sources, options = {})
source_requirements[name] = SystemGemSource.instance
end
+ # Check to see whether the existing cache meets all the requirements
begin
valid = Resolver.resolve(dependencies, [source_index], source_requirements)
rescue Bundler::GemNotFound
end
- if options[:cached]
- sources = sources.select { |s| s.can_be_local? }
- end
+ sources = only_local(sources) if options[:cached]
+ # Check the remote sources if the existing cache does not meet the requirements
+ # or the user passed --update
if options[:update] || !valid
Bundler.logger.info "Calculating dependencies..."
bundle = Resolver.resolve(dependencies, [@cache] + sources, source_requirements)
@@ -61,7 +62,7 @@ def prune(dependencies, sources)
s.local = true
end
- sources = sources.select { |s| s.can_be_local? }
+ sources = only_local(sources)
bundle = Resolver.resolve(dependencies, [@cache] + sources)
@cache.gems.each do |name, spec|
unless bundle.any? { |s| s.name == spec.name && s.version == spec.version }
@@ -87,6 +88,10 @@ def download_path_for(type)
private
+ def only_local(sources)
+ sources.select { |s| s.can_be_local? }
+ end
+
def download(bundle, options)
bundle.sort_by {|s| s.full_name.downcase }.each do |spec|
next if options[:no_bundle].include?(spec.name)
@@ -216,16 +221,18 @@ def load_paths_for_specs(specs, options)
specs.each do |spec|
next if options[:no_bundle].include?(spec.name)
gem_path = Pathname.new(spec.full_gem_path)
- if spec.bindir
- load_paths << gem_path.join(spec.bindir).relative_path_from(@path).to_s
- end
+ load_paths << load_path_for(gem_path, spec.bindir) if spec.bindir
spec.require_paths.each do |path|
- load_paths << gem_path.join(path).relative_path_from(@path).to_s
+ load_paths << load_path_for(gem_path, path)
end
end
load_paths
end
+ def load_path_for(gem_path, path)
+ gem_path.join(path).relative_path_from(@path).to_s
+ end
+
def spec_file_for(spec)
spec.loaded_from.relative_path_from(@path).to_s
end

0 comments on commit 68d4ebe

Please sign in to comment.