From c6a0405401e9bad3f27e5078ac42b3c56172bbb0 Mon Sep 17 00:00:00 2001 From: Michal Papis Date: Fri, 20 Dec 2013 08:24:56 +0100 Subject: [PATCH] move getting gem specifications to gem-empty/specification --- lib/gem-empty/command.rb | 10 ++-------- lib/gem-empty/specification.rb | 16 ++++++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/gem-empty/command.rb b/lib/gem-empty/command.rb index fcfd69f..12aa3e7 100644 --- a/lib/gem-empty/command.rb +++ b/lib/gem-empty/command.rb @@ -1,3 +1,4 @@ +require 'gem-empty/specification' require 'rubygems/command_manager' require 'rubygems/uninstaller' require 'rubygems/version' @@ -44,16 +45,9 @@ def execute(options = {}) def gem_dir_specs @gem_dir_specs ||= - installed_gems.select do |spec| + GemEmpty::Specification.installed_gems.select do |spec| File.exists?( File.join( Gem.dir, 'gems', spec.full_name ) ) end end - def installed_gems - if Gem::VERSION > '1.8' then - Gem::Specification.to_a - else - Gem.source_index.map{|name,spec| spec} - end - end end diff --git a/lib/gem-empty/specification.rb b/lib/gem-empty/specification.rb index f2a2249..944a861 100644 --- a/lib/gem-empty/specification.rb +++ b/lib/gem-empty/specification.rb @@ -1,14 +1,14 @@ module GemEmpty module Specification + def self.installed_gems + if Gem::VERSION > '1.8' then + Gem::Specification.to_a + else + Gem.source_index.map{|name,spec| spec} + end + end def self.find(name = "gem-empty") - @gem_empty_spec ||= - if Gem::Specification.respond_to?(:find_by_name) - Gem::Specification.find_by_name(name) - else - Gem.source_index.find_name(name).last - end - rescue Gem::LoadError - nil + @gem_empty_spec ||= installed_gems.find{|spec| spec.name == name} end def self.version find ? find.version.to_s : nil