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 =<<INFO

ruby:
interpreter:  "#{ruby_version.interpreter}"
version:      "#{ruby_version.version}"
date:         "#{ruby_version.date}"
platform:     "#{ruby_version.platform}"
patchlevel:   "#{ruby_version.patchlevel}"
full_version: "#{ruby_version.full_version}"

homes:
gem:          "#{gem_home}"
ruby:         "#{ruby.dirname}"

binaries:
ruby:         "#{ruby}"
irb:          "#{Which::Irb.exe}"
gem:          "#{Which::Gem.exe}"
rake:         "#{Which::Rake.exe}"

environment:
GEM_HOME:     "#{ENV['GEM_HOME']}"
HOME:         "#{ENV['HOME']}"
IRBRC:        "#{ENV['IRBRC']}"
RUBYOPT:      "#{ENV['RUBYOPT']}"

file associations:
.rb:           #{file_associations('.rb')}
.rbw:          #{file_associations('.rbw')}
INFO
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 =<<MSG

Pik info will not work unless there is a version of ruby in the path.

You can use pik switch to add one.
MSG
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 =<<MSG
  
warning: There is more than one version of ruby in the system path
#{dirs.join("\n")}
MSG
end