class Reditor::Command

Attributes

restarted[RW]

Public Class Methods

restart(args) click to toggle source
# File lib/reditor/command.rb, line 11
def restart(args)
  self.restarted = true

  start args
end

Public Instance Methods

open(name = nil) click to toggle source
# File lib/reditor/command.rb, line 27
def open(name = nil)
  return invoke :help unless name

  detect_exec name, global: options[:global] do |dir, file|
    say "Moving to #{dir}", :green
    Dir.chdir dir do
      say "Opening #{file}", :green

      exec editor_command, file
    end
  end
end
sh(name) click to toggle source
# File lib/reditor/command.rb, line 42
def sh(name)
  detect_exec name, global: options[:global] do |dir, _|
    say "Moving to #{dir}", :green
    Dir.chdir dir do
      exec shell_command
    end
  end
end
version() click to toggle source
# File lib/reditor/command.rb, line 52
def version
  say "Reditor version #{VERSION}"
end

Private Instance Methods

choose_exec(name, options = {}, &block) click to toggle source
# File lib/reditor/command.rb, line 68
def choose_exec(name, options = {}, &block)
  names = LibrarySearchQuery.search(name, options)

  if name = Pepin.search(names)
    do_exec LibraryLocator.detect!(name, options), &block
  else
    abort "#{num} isn't included in the list."
  end
rescue LibraryNotFound => e
  abort e.message
rescue Interrupt
  exit_silently
end
detect_exec(name, options = {}, &block) click to toggle source
# File lib/reditor/command.rb, line 58
def detect_exec(name, options = {}, &block)
  path = LibraryLocator.detect!(name, options)

  do_exec path, &block
rescue LibraryNotFound => e
  say e.message

  choose_exec name, options, &block
end
do_exec(path, &block) click to toggle source
# File lib/reditor/command.rb, line 82
def do_exec(path, &block)
  dir, file =
    if path.file?
      [path.dirname.to_path, path.basename.to_path]
    else
      [path.to_path, '.']
    end

  block.call dir, file
end
editor_command() click to toggle source
# File lib/reditor/command.rb, line 93
def editor_command
  ENV['EDITOR'] or raise '$EDITOR is not provided.'
end
exit_silently() click to toggle source
# File lib/reditor/command.rb, line 101
def exit_silently
  puts

  exit
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/reditor/command.rb, line 107
def method_missing(name, *args, &block)
  return super if Command.restarted

  Command.restart ['open', name.to_s, *args]
end
shell_command() click to toggle source
# File lib/reditor/command.rb, line 97
def shell_command
  ENV['SHELL'] or raise '$SHELL is not provided.'
end