Class: IRB::BaseCompletor

Inherits:
Object show all
Defined in:
lib/irb/completion.rb

Overview

:nodoc:

Direct Known Subclasses

RegexpCompletor, TypeCompletor

Constant Summary collapse

HELP_COMMAND_PREPOSING =

Set of reserved words used by Ruby, you should not use these for constants or variables

/\Ahelp\s+/
GEM_PATHS =
if defined?(Gem::Specification)
  Gem::Specification.latest_specs(true).map { |s|
    s.require_paths.map { |p|
      if File.absolute_path?(p)
        p
      else
        File.join(s.full_gem_path, p)
      end
    }
  }.flatten
else
  []
end.freeze

Instance Method Summary collapse

Instance Method Details

#command_candidates(target) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/irb/completion.rb', line 94

def command_candidates(target)
  if !target.empty?
    IRB::Command.command_names.select { _1.start_with?(target) }
  else
    []
  end
end

#command_document_target(preposing, matched) ⇒ Object



102
103
104
105
106
# File 'lib/irb/completion.rb', line 102

def command_document_target(preposing, matched)
  if preposing.empty? && IRB::Command.command_names.include?(matched)
    CommandDocument.new(matched)
  end
end

#completion_candidates(preposing, target, postposing, bind:) ⇒ Object

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/irb/completion.rb', line 41

def completion_candidates(preposing, target, postposing, bind:)
  raise NotImplementedError
end

#doc_namespace(preposing, matched, postposing, bind:) ⇒ Object

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/irb/completion.rb', line 45

def doc_namespace(preposing, matched, postposing, bind:)
  raise NotImplementedError
end

#retrieve_files_to_require_from_load_pathObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/irb/completion.rb', line 75

def retrieve_files_to_require_from_load_path
  @files_from_load_path ||=
    (
      shortest = []
      rest = retrieve_gem_and_system_load_path.each_with_object([]) { |path, result|
        begin
          names = Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
        rescue Errno::ENOENT
          nil
        end
        next if names.empty?
        names.map! { |n| n.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '') }.sort!
        shortest << names.shift
        result.concat(names)
      }
      shortest.sort! | rest
    )
end

#retrieve_files_to_require_relative_from_current_dirObject



108
109
110
111
112
# File 'lib/irb/completion.rb', line 108

def retrieve_files_to_require_relative_from_current_dir
  @files_from_current_dir ||= Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: '.').map { |path|
    path.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '')
  }
end

#retrieve_gem_and_system_load_pathObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/irb/completion.rb', line 64

def retrieve_gem_and_system_load_path
  candidates = (GEM_PATHS | $LOAD_PATH)
  candidates.filter_map do |p|
    if p.respond_to?(:to_path)
      p.to_path
    else
      String(p) rescue nil
    end
  end.sort
end