Class: RSpec::Interactive::InputCompleter

Inherits:
Pry::InputCompleter
  • Object
show all
Defined in:
lib/rspec-interactive/input_completer.rb

Instance Method Summary collapse

Instance Method Details

#call(str, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rspec-interactive/input_completer.rb', line 18

def call(str, options = {})
  rspec_completions = cli_completions('rspec', str)
  return rspec_completions if rspec_completions

  rubocop_completions = cli_completions('rubocop', str)
  return rubocop_completions if rubocop_completions

  super
end

#cli_completions(command, string) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rspec-interactive/input_completer.rb', line 4

def cli_completions(command, string)
  line = Readline.line_buffer
  before_current = Readline.point == string.length ? '' :  line[0..(Readline.point - string.length)]
  before_cursor = line[0..(Readline.point - 1)]

  if line.match(/^ *#{command} +/)
    Dir[string + '*'].map { |filename| File.directory?(filename) ? "#{filename}/" : filename }
  elsif before_current.strip.empty? && command.match(/^#{Regexp.escape(string)}/)
    ["#{command} "]
  else
    nil
  end
end