module Rails::Sh::Command

Public Class Methods

[](name) click to toggle source
# File lib/rails/sh/command.rb, line 28
def [](name)
  commands[name.to_sym]
end
clear() click to toggle source
# File lib/rails/sh/command.rb, line 54
def clear
  commands.clear
  completions.clear
end
command_names() click to toggle source
# File lib/rails/sh/command.rb, line 24
def command_names
  commands.keys
end
commands() click to toggle source
# File lib/rails/sh/command.rb, line 5
def commands
  @commands ||= {}
end
completion_proc() click to toggle source
# File lib/rails/sh/command.rb, line 32
def completion_proc
  lambda { |line|
    regex = /#{Regexp.quote(line)}/
    completions.map { |completion|
      case completion
      when String
        completion if completion.match(regex)
      when Proc
        completion.call(line)
      end
    }.compact
  }
end
completions() click to toggle source
# File lib/rails/sh/command.rb, line 46
def completions
  @completions ||= []
end
completions=(completions) click to toggle source
# File lib/rails/sh/command.rb, line 50
def completions=(completions)
  @completions = completions
end
define(*names, &block) click to toggle source
# File lib/rails/sh/command.rb, line 9
def define(*names, &block)
  names.each do |name|
    commands[name.to_sym] = block
    completions << name.to_s
  end
end
find(line) click to toggle source
# File lib/rails/sh/command.rb, line 16
def find(line)
  if name = line.split(/\s+/, 2)[0]
    commands[name.to_sym]
  else
    nil
  end
end