Module: Ripl::Runner::API
- Included in:
- Ripl::Runner
- Defined in:
- lib/ripl/runner.rb
Instance Method Summary collapse
- #format_error(err) ⇒ Object
- #load_rc(file) ⇒ Object
- #parse_option(option, argv) ⇒ Object
- #parse_options(argv) ⇒ Object
- #run(argv = ARGV) ⇒ Object
- #run_command(argv) ⇒ Object
- #start(options = {}) ⇒ Object
Instance Method Details
#format_error(err) ⇒ Object
74 75 76 |
# File 'lib/ripl/runner.rb', line 74 def format_error(err) "#{err.class}: #{err.}\n #{err.backtrace.join("\n ")}" end |
#load_rc(file) ⇒ Object
68 69 70 71 72 |
# File 'lib/ripl/runner.rb', line 68 def load_rc(file) load file if File.exists?(File.(file)) rescue StandardError, SyntaxError warn "ripl: Error while loading #{file}:\n"+ format_error($!) end |
#parse_option(option, argv) ⇒ Object
51 52 53 |
# File 'lib/ripl/runner.rb', line 51 def parse_option(option, argv) warn "ripl: invalid option `#{option.sub(/^-+/, '')}'" end |
#parse_options(argv) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ripl/runner.rb', line 26 def (argv) while argv[0] =~ /^-/ case argv.shift when /-I=?(.*)/ $LOAD_PATH.unshift(*($1.empty? ? argv.shift.to_s : $1).split(":")) when /-r=?(.*)/ require $1.empty? ? argv.shift.to_s : $1 when '-d' $DEBUG = true when '-v', '--version' puts Ripl::VERSION; exit when '-f' ENV['RIPL_IRBRC'] = 'false' when '-h', '--help' name_max = OPTIONS.map {|e| e[0].length }.max desc_max = OPTIONS.map {|e| e[1].length }.max puts "Usage: ripl [OPTIONS] [COMMAND] [ARGS]", "\nOptions:", OPTIONS.map {|k,v| " %-*s %-*s" % [name_max, k, desc_max, v] } exit when /^(--?[^-]+)/ parse_option($1, argv) end end end |
#run(argv = ARGV) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/ripl/runner.rb', line 18 def run(argv=ARGV) ENV['RIPLRC'] = 'false' if argv.delete('-F') load_rc(Ripl.config[:riplrc]) unless ENV['RIPLRC'] == 'false' @run = true (argv) argv[0] ? run_command(argv) : start end |
#run_command(argv) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/ripl/runner.rb', line 55 def run_command(argv) exec "ripl-#{argv.shift}", *argv rescue Errno::ENOENT raise unless $!. =~ /No such file or directory.*ripl-(\w+)/ abort "`#{$1}' is not a ripl command." end |