Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use attr instead of instance variable

  • Loading branch information...
commit 67d175aaceeaab20425e19d574eb0a449622ccd5 1 parent 972e915
@vertiginous authored
View
38 lib/pik/commands/add_command.rb
@@ -5,17 +5,15 @@ class Add < Command
it 'Adds another ruby location to pik.'
include ConfigFileEditor
- attr_reader :interactive
-
def execute(path=nil)
return add_interactive if interactive
path = @args.first || Which::Ruby.find
- add(path)
+ add(Pathname(path))
end
def add(path)
- path = Pathname.new(path)
path = path.dirname if path.file?
+
if Which::Ruby.exist?(path)
if find_config_from_path(path)
puts "This version has already been added."
@@ -33,9 +31,9 @@ def add(path)
Log.info "Adding: #{name}\n Located at: #{path}\n"
- @config[name] = {}
- @config[name][:path] = path
- @config[name][:version] = version.full_version
+ config[name] = {}
+ config[name][:path] = path
+ config[name][:version] = version.full_version
end
else
puts "Couldn't find a Ruby version at #{path}"
@@ -45,10 +43,6 @@ def add(path)
def command_options
super
options.banner += "[path_to_ruby]"
- options.separator ""
- options.on("--interactive", "-i", "Add interactively") do |value|
- @interactive = value
- end
end
def get_version(path=Which::Ruby.find)
@@ -57,28 +51,6 @@ def get_version(path=Which::Ruby.find)
version = VersionParser.parse(ruby_ver)
end
- def add_interactive
- hl.choose do |menu|
- menu.prompt = ""
- menu.choice('e]nter a path') do
- dir = hl.ask("Enter a path to a ruby/bin dir (enter to quit)")
- execute(dir) unless dir.empty? || !hl.agree("Add '#{dir}'?"){|answer| answer.default = 'yes' }
- add_interactive
- end
- menu.choice('s]earch') do
- search_dir = hl.ask("Enter a search path")
- files = Which::Ruby.glob(search_dir + '**')
- files.uniq.each do |file|
- dir = File.dirname(file)
- add(dir) if hl.agree("Add '#{dir}'?"){|answer| answer.default = 'yes' }
- end
- add_interactive
- end
- menu.choice('q]uit'){raise QuitError}
- end
-
- end
-
def modify_version(version)
puts "This version appears to already be installed at this location:\n\n"
puts " #{config[version][:path]}\n\n"
View
4 lib/pik/commands/config_file_editor.rb
@@ -2,9 +2,9 @@ module Pik
module ConfigFileEditor
- def initialize(args=ARGV,config=nil)
+ def initialize(args=ARGV,config_=nil)
super
- editors << @config
+ editors << config
end
end
View
3  lib/pik/commands/install_command.rb
@@ -65,8 +65,7 @@ def handle_target
end
def add(target)
- puts
- p = Pik::Add.new([target + 'bin'], @config)
+ p = Pik::Add.new([target + 'bin'], config)
p.execute
p.close
end
View
6 lib/pik/commands/refresh_command.rb
@@ -8,8 +8,8 @@ class Refresh < Command
def execute
Log.info "Refreshing the list of installed rubies."
- old_config = @config.rubies.dup
- @config.rubies.clear
+ old_config = config.rubies.dup
+ config.rubies.clear
old_config.each do |version,hash|
@@ -18,7 +18,7 @@ def execute
end
def add_cmd
- @add_cmd ||= Pik::Add.new([], @config)
+ @add_cmd ||= Pik::Add.new([], config)
end
end
View
6 lib/pik/commands/run_command.rb
@@ -80,10 +80,10 @@ def check_args
end
def rubies
- if versions = @config.options[:versions]
- versions.split(',').map{|v| @config.match(v) }
+ if versions = config.options[:versions]
+ versions.split(',').map{|v| config.match(v) }
else
- @config
+ config
end
end
View
2  lib/pik/commands/uninstall_command.rb
@@ -9,7 +9,7 @@ class UnInstall < Command
attr_reader :force
def execute
- to_remove = @config.match(@args.first)
+ to_remove = config.match(@args.first)
unless to_remove
puts "Couldn't find the version you're looking for '#{@args.join(' ')}'."
raise QuitError
View
4 lib/pik/commands/use_command.rb
@@ -11,12 +11,12 @@ class Use < Command
attr_accessor :default
def execute
- new_ver = @config.options.fetch(:use, @config.match(@args.shift))
+ new_ver = config.options.fetch(:use, config.match(@args.shift))
abort('Nothing matches:') unless new_ver
ver_name, ver_config = *new_ver
- @config.global[:default] = VersionPattern.full(ver_name) if default
+ config.global[:default] = VersionPattern.full(ver_name) if default
switch_path_to(ver_config)
switch_gem_home_to(ver_config[:gem_home])
Please sign in to comment.
Something went wrong with that request. Please try again.