Module: Ripl::Runner::API

Included in:
Ripl::Runner
Defined in:
lib/ripl/runner.rb

Instance Method Summary collapse

Instance Method Details

#format_error(err) ⇒ Object



52
53
54
# File 'lib/ripl/runner.rb', line 52

def format_error(err)
  "#{err.class}: #{err.message}\n    #{err.backtrace.join("\n    ")}"
end

#load_rc(file) ⇒ Object



46
47
48
49
50
# File 'lib/ripl/runner.rb', line 46

def load_rc(file)
  load file if File.exists?(File.expand_path(file))
rescue StandardError, SyntaxError
  warn "Error while loading #{file}:\n"+ format_error($!)
end

#parse_options(argv) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ripl/runner.rb', line 14

def parse_options(argv)
  while argv[0] =~ /^-/
    case argv.shift
    when /-I=?(.*)/
      $LOAD_PATH.unshift(*$1.split(":"))
    when /-r=?(.*)/
      require $1
    when '-d'
      $DEBUG = true
    when '-v', '--version'
      puts Ripl::VERSION; exit
    when '-f'
      ENV['RIPL_IRBRC'] = 'false'
    when '-h', '--help'
      puts IO.readlines(__FILE__).grep(/^#/).map {|e| e.sub(/^#\s/,'') }; exit
    end
  end
end

#runObject



7
8
9
10
11
12
# File 'lib/ripl/runner.rb', line 7

def run
  load_rc(Ripl.config[:riplrc])
  @riplrc = true
  parse_options(ARGV)
  ARGV[0] ? run_command(ARGV) : start
end

#run_command(argv) ⇒ Object



33
34
35
36
37
38
# File 'lib/ripl/runner.rb', line 33

def run_command(argv)
  exec "ripl-#{argv.shift}", *argv
rescue Errno::ENOENT
  raise unless $!.message =~ /No such file or directory.*ripl-(\w+)/
  abort "`#{$1}' is not a ripl command."
end

#start(options = {}) ⇒ Object



40
41
42
43
44
# File 'lib/ripl/runner.rb', line 40

def start(options={})
  load_rc(Ripl.config[:riplrc]) unless @riplrc
  Ripl.config[:irbrc] = ENV['RIPL_IRBRC'] != 'false' if ENV['RIPL_IRBRC']
  Ripl.shell(options).loop
end