diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-04-12 10:26:29 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-04-12 10:26:29 -0500 |
commit | 342dcfe789d11e07f89d4ddfc3dc581da650a65e (patch) | |
tree | 766fd0cabb0090b7f85bfa5a809997cfaf3da9db /railties/lib/rails | |
parent | b8bc92e61914cc6ef9d6ca12aba27d440ec0ebd5 (diff) | |
parent | 60be4b09f51d2560802ebd744893bb6f737ef57c (diff) | |
download | rails-342dcfe789d11e07f89d4ddfc3dc581da650a65e.tar.gz rails-342dcfe789d11e07f89d4ddfc3dc581da650a65e.tar.bz2 rails-342dcfe789d11e07f89d4ddfc3dc581da650a65e.zip |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/gem_dependency.rb | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index 45d838bcc1..3985443ceb 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -8,11 +8,17 @@ module Rails def initialize(name, options = {}) require 'rubygems' unless Object.const_defined?(:Gem) - @name = name.to_s - if options[:version] + + if options[:requirement] + @requirement = options[:requirement] + elsif options[:version] @requirement = Gem::Requirement.create(options[:version]) - @version = @requirement.instance_variable_get("@requirements").first.last + else + raise ArgumentError.new('Must pass either :version or :requirement') end + + @version = @requirement.instance_variable_get("@requirements").first.last if @requirement + @name = name.to_s @lib = options[:lib] @source = options[:source] @loaded = @frozen = @load_paths_added = false @@ -35,6 +41,14 @@ module Rails puts $!.to_s end + def dependencies + all_dependencies = specification.dependencies.map do |dependency| + GemDependency.new(dependency.name, :requirement => dependency.version_requirements) + end + all_dependencies += all_dependencies.map(&:dependencies).flatten + all_dependencies.uniq + end + def gem_dir(base_directory) File.join(base_directory, specification.full_name) end @@ -64,10 +78,6 @@ module Rails Gem::GemRunner.new.run(install_command) end - def specification - @spec ||= Gem.source_index.search(Gem::Dependency.new(@name, @requirement)).sort_by { |s| s.version }.last - end - def unpack_to(directory) FileUtils.mkdir_p directory Dir.chdir directory do @@ -83,6 +93,16 @@ module Rails end end + def ==(other) + self.name == other.name && self.requirement == other.requirement + end + +private ################################################################### + + def specification + @spec ||= Gem.source_index.search(Gem::Dependency.new(@name, @requirement)).sort_by { |s| s.version }.last + end + def install_command cmd = %w(install) << @name cmd << "--version" << "#{@requirement.to_s}" if @requirement |