Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor common_methods and add RubyGems 1.8 layer

  • Loading branch information...
commit 2f37fce6acf350df26a21eb8c466a3eb04153abf 1 parent 6972215
@ferrous26 authored
Showing with 60 additions and 31 deletions.
  1. +60 −31 lib/rubygems-compile/common_methods.rb
View
91 lib/rubygems-compile/common_methods.rb
@@ -1,44 +1,73 @@
-module Gem
+module Gem::CompileMethods
+if Gem::VERSION.to_f < 1.8
- module CompileMethods
+ def execution_list
+ return all_gemspecs if options[:all]
- def execution_list
- gems_list.map do |gem|
- candidates = Gem.source_index.find_name(gem, options[:version])
+ specs = get_all_gem_names.map do |gem|
+ candidates = Gem.source_index.find_name(gem, options[:version])
- if candidates.empty?
- alert_error "#{gem} is not installed. Skipping."
- next
- end
+ if candidates.empty?
+ alert_error "#{gem} is not installed. Skipping."
+ next
+ end
- candidates << dependencies_for(*candidates) unless options[:ignore]
- candidates
+ candidates << dependencies_for(candidates) unless options[:ignore]
+ candidates
end
- gems.flatten!
- gems.uniq!
- gems.delete_if { |spec| spec.name == 'rubygems-compile' }
- gems
+ specs.flatten!
+ specs.uniq!
+ specs.delete_if { |spec| spec.name == 'rubygems-compile' }
+ specs
end
- def gems_list
- # @todo Gem.source_index is going away...
- installed_gems = Gem.source_index.all_gems
- if options[:all] then
- installed_gems.map { |_, spec| spec.name }
- else
- get_all_gem_names
- end
- end
- def dependencies_for *specs
- specs.map { |spec|
- spec.runtime_dependencies.map { |dep|
- deps = Gem.source_index.find_name(dep.name,dep.requirement)
- deps + dependencies_for(*deps)
- }
+ private
+
+ def all_gemspecs
+ specs = Gem.source_index.all_gems.map(&:last)
+ specs.select { |spec| spec.name != 'rubygems-compile' }
+ end
+
+ def dependencies_for specs
+ specs.map { |spec|
+ spec.runtime_dependencies.map { |dep|
+ deps = Gem.source_index.find_name(dep.name, dep.requirement)
+ deps + dependencies_for(*deps)
}
- end
+ }
+ end
+
+else
+ def execution_list
+ return all_gemspecs if options[:all]
+
+ specs = get_all_gem_names.map { |gem|
+ names = Gem::Specification.find_all_by_name(gem, options[:version])
+ names << dependencies_for specs unless options[:ignore]
+ }
+ specs.flatten!
+ specs.uniq!
+ specs.delete_if { |spec| spec.name == 'rubygems_compile' }
+ specs
+ end
+
+
+ private
+
+ def all_gemspecs
+ Gem::Specification.map(&:name).select { |name| name != 'rubygems-compile' }
end
+ def dependencies_for specs
+ specs.map { |spec|
+ spec.runtime_dependencies.map { |dep|
+ deps = Gem::Specification.find_all_by_name(dep.name, dep.requirement)
+ deps + dependencies_for(*deps)
+ }
+ }
+ end
+
+end
end
Please sign in to comment.
Something went wrong with that request. Please try again.