Module: Rails::Sh

Defined in:
lib/rails/sh.rb,
lib/rails/sh/rake.rb,
lib/rails/sh/rails.rb,
lib/rails/sh/bundler.rb,
lib/rails/sh/command.rb,
lib/rails/sh/helpers.rb,
lib/rails/sh/forkable.rb

Defined Under Namespace

Modules: Bundler, Command, Forkable, Helpers, Rails, Rake

Class Method Summary collapse

Class Method Details

.execute(line) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/rails/sh.rb', line 47

def execute(line)
  if command = Command.find(line)
    start = Time.now
    arg = line.split(/\s+/, 2)[1] rescue nil
    command.call(arg)
    puts "\e[34m#{Time.now - start}sec\e[0m"
  else
    puts "\e[41mCommand not found\e[0m"
  end
end

.promptObject



38
39
40
# File 'lib/rails/sh.rb', line 38

def prompt
  "%s> " % "rails-sh(#{::Rails.root.basename})"
end

.setup_readlineObject



42
43
44
45
# File 'lib/rails/sh.rb', line 42

def setup_readline
  Readline.basic_word_break_characters = ""
  Readline.completion_proc = Command.completion_proc
end

.startObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rails/sh.rb', line 12

def start
  ::Rails::Sh::Rails.init
  ::Rails::Sh::Rake.init

  require 'rails/sh/commands'

  begin; load "~/.railsshrc"; rescue LoadError; end

  puts "\e[36mRails.env: #{::Rails.env}\e[0m"
  puts "\e[36mtype `help` to print help\e[0m"

  setup_readline
  while buf = Readline.readline(prompt, true)
    line = buf.strip
    next if line.empty?
    begin
      execute(line)
    rescue SystemExit
      raise
    rescue Exception => e
      puts "\e[41m#{e.message}\n#{e.backtrace.join("\n")}\e[0m"
    end
    setup_readline
  end
end