Class: PatchIRBCompletion::Suggest

Inherits:
Object
  • Object
show all
Defined in:
lib/patch_irb_completion/suggest.rb

Class Method Summary collapse

Class Method Details

.callObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/patch_irb_completion/suggest.rb', line 35

def self.call
  filename = find_completion_source_in_current_ruby_version
  if check_if_completion_source_file_has_offending_code(filename)
    puts <<EOT
The file \"#{filename}\" has not been patched... I would suggest you replace:
bind = IRB.conf[:MAIN_CONTEXT].workspace.binding (line 38)
with:
context = IRB.conf[:MAIN_CONTEXT]
bind = context ? context.workspace.binding : binding
EOT
  else
    puts "The file \"#{filename}\" is patched."
  end
end

.check_if_completion_source_file_has_offending_code(filename) ⇒ Object



30
31
32
33
# File 'lib/patch_irb_completion/suggest.rb', line 30

def self.check_if_completion_source_file_has_offending_code(filename)
  unpatched_code = "IRB.conf[:MAIN_CONTEXT].workspace"
  File.read(filename).include?(unpatched_code)
end

.find_completion_source_in_current_ruby_versionObject



22
23
24
25
26
27
28
# File 'lib/patch_irb_completion/suggest.rb', line 22

def self.find_completion_source_in_current_ruby_version
  $:.each do |lib_dir|
    completion_file = find_completion_source_in_dir(lib_dir)
    next unless completion_file
    return completion_file
  end
end

.find_completion_source_in_dir(dir) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/patch_irb_completion/suggest.rb', line 13

def self.find_completion_source_in_dir(dir)
  Find.find(dir) do |filename|
    # puts filename
    next unless File.basename(filename) == "completion.rb"
    return filename
  end
  nil
end

.find_ruby_lib_pathObject



5
6
7
8
9
10
11
# File 'lib/patch_irb_completion/suggest.rb', line 5

def self.find_ruby_lib_path
  ruby_bin_path = `which ruby`
  ruby_path = File.expand_path(File.join(ruby_bin_path, "..", "..", "lib"))
  unless File.exist?(ruby_path)
    ruby_path = `ruby -e "puts $:[0]"`
  end
end