Class: Pik::Info

Inherits:
Command show all
Defined in:
lib/pik/commands/info_command.rb

Instance Attribute Summary

Attributes inherited from Command

#config, #debug, #options, #output, #version

Instance Method Summary collapse

Methods inherited from Command

#actual_gem_home, #add_sigint_handler, aka, choose_from, #close, cmd_name, #cmd_name, #command_options, #create, #current_gem_bin_path, #current_version?, #default_gem_home, #delete_old_pik_script, description, #editors, #find_config_from_path, #gem_path, #get_version, hl, inherited, #initialize, it, names, #parse_options, #pik_version, #sh, summary

Constructor Details

This class inherits a constructor from Pik::Command

Instance Method Details

#check_pathObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pik/commands/info_command.rb', line 51

def check_path
  dirs = Which::Ruby.find_all
  case dirs.size 
  when 0
    $stdout.flush
    abort no_ruby
  when 1
    dirs.first
  else
    puts too_many_rubies(dirs)
    dirs.first
  end
end

#executeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pik/commands/info_command.rb', line 9

def execute
  puts pik_version
  
  ruby = check_path
  
  ruby_version = find_config_from_path(ruby)
  current = config[ruby_version]
  gem_home = current[:gem_home] || actual_gem_home
  ruby_version = Pik::VersionParser.parse(ruby_version)

  puts info ="\nruby:\ninterpreter:  \"\#{ruby_version.interpreter}\"\nversion:      \"\#{ruby_version.version}\"\ndate:         \"\#{ruby_version.date}\"\nplatform:     \"\#{ruby_version.platform}\"\npatchlevel:   \"\#{ruby_version.patchlevel}\"\nfull_version: \"\#{ruby_version.full_version}\"\n\nhomes:\ngem:          \"\#{gem_home}\"\nruby:         \"\#{ruby.dirname}\"\n\nbinaries:\nruby:         \"\#{ruby}\"\nirb:          \"\#{Which::Irb.exe}\"\ngem:          \"\#{Which::Gem.exe}\"\nrake:         \"\#{Which::Rake.exe}\"\n\nenvironment:\nGEM_HOME:     \"\#{ENV['GEM_HOME']}\"\nHOME:         \"\#{ENV['HOME']}\"\nIRBRC:        \"\#{ENV['IRBRC']}\"\nRUBYOPT:      \"\#{ENV['RUBYOPT']}\"\n\nfile associations:\n.rb:           \#{file_associations('.rb')}\n.rbw:          \#{file_associations('.rbw')}\n"
end

#file_associations(extension) ⇒ Object



82
83
84
85
86
# File 'lib/pik/commands/info_command.rb', line 82

def file_associations(extension)
  @reg = Reg.new
  assoc = @reg.hkcr(extension) rescue nil
  ftype = @reg.hkcr("#{assoc}\\Shell\\open\\command") rescue nil
end

#no_rubyObject



73
74
75
76
77
78
79
80
# File 'lib/pik/commands/info_command.rb', line 73

def no_ruby
  msg ="\nPik info will not work unless there is a version of ruby in the path.\n\nYou can use pik switch to add one.\n"
end

#too_many_rubies(dirs) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/pik/commands/info_command.rb', line 65

def too_many_rubies(dirs)
  msg ="  \nwarning: There is more than one version of ruby in the system path\n\#{dirs.join(\"\\n\")}\n"
end