Class: Pik::Add
- Includes:
- ConfigFileEditor
- Defined in:
- lib/pik/commands/add_command.rb
Instance Attribute Summary collapse
-
#interactive ⇒ Object
readonly
Returns the value of attribute interactive.
Attributes inherited from Command
#config, #debug, #options, #output, #version
Instance Method Summary collapse
- #add(path) ⇒ Object
- #add_interactive ⇒ Object
- #command_options ⇒ Object
- #execute(path = nil) ⇒ Object
Methods included from ConfigFileEditor
Methods inherited from Command
#actual_gem_home, #add_sigint_handler, aka, choose_from, clean_gem_batch, #close, cmd_name, #cmd_name, #create, #current_gem_bin_path, #current_version?, #default_gem_home, #delete_old_pik_batches, description, #editors, #find_config_from_path, #get_gem_home, #get_version, hl, inherited, #initialize, it, names, #parse_options, #pik_version, #sh, summary
Instance Attribute Details
#interactive ⇒ Object (readonly)
Returns the value of attribute interactive.
8 9 10 |
# File 'lib/pik/commands/add_command.rb', line 8 def interactive @interactive end |
Instance Method Details
#add(path) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pik/commands/add_command.rb', line 16 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." else version = get_version(path) path = Pathname(path..to_ruby) puts "** Adding: #{version}\n Located at: #{path}\n" @config[version] = {} @config[version][:path] = path end else puts "Couldn't find a Ruby version at #{path}" end end |
#add_interactive ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pik/commands/add_command.rb', line 43 def add_interactive @hl.choose do || .prompt = "" .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 .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 .choice('q]uit'){raise QuitError} end end |
#command_options ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/pik/commands/add_command.rb', line 34 def super . += "[path_to_ruby]" .separator "" .on("--interactive", "-i", "Add interactively") do |value| @interactive = value end end |