Skip to content

Commit

Permalink
Refactor option management a bit to set default options on initialize…
Browse files Browse the repository at this point in the history
… and override them via #execute
  • Loading branch information
Andy Fleener committed Apr 19, 2015
1 parent 51795e9 commit 459a588
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/gem-empty/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand All @@ -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

Expand Down

0 comments on commit 459a588

Please sign in to comment.