From 459a5884a3d3b4a40d3016e75cfd8fdee65ba802 Mon Sep 17 00:00:00 2001 From: Andy Fleener Date: Sun, 19 Apr 2015 09:52:34 -0500 Subject: [PATCH] Refactor option management a bit to set default options on initialize and override them via #execute --- lib/gem-empty/command.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/gem-empty/command.rb b/lib/gem-empty/command.rb index 2c78953..dec6f2a 100644 --- a/lib/gem-empty/command.rb +++ b/lib/gem-empty/command.rb @@ -4,8 +4,11 @@ require 'rubygems/version' class EmptyCommand < Gem::Command + attr_accessor :options + def initialize super 'empty', 'Remove all gems from current GEM_HOME.' + self.options = { :install_dir => Gem.dir, :force => true, :executables => true } end def arguments # :nodoc: @@ -26,8 +29,8 @@ def description # :nodoc: DOC end - def execute(options = {}) - options = {:force => true, :executables => true }.merge(options) + def execute(opts = {}) + self.options = options.merge(opts) uninstaller = Gem::Uninstaller.new(nil, options) uninstaller.remove_all(gem_dir_specs) @@ -44,7 +47,7 @@ def execute(options = {}) def gem_dir_specs @gem_dir_specs ||= GemEmpty::Specification.installed_gems.select do |spec| - File.exists?( File.join( Gem.dir, 'gems', spec.full_name ) ) + File.exists?( File.join( options[:install_dir], 'gems', spec.full_name ) ) end end