Class: Resque::Pool::Dynamic::Shell
- Inherits:
-
Ripl::Shell
- Object
- Ripl::Shell
- Resque::Pool::Dynamic::Shell
- Defined in:
- lib/resque/pool/dynamic/shell.rb
Overview
Ripl shell subclassed for nicer CLI experience
Class Method Summary collapse
-
.run(instance, opts = {}) ⇒ Object
Run the Ripl shell in context of specified instance.
Instance Method Summary collapse
-
#eval_input(input) ⇒ Object
Handle help as special command.
-
#help(subject = nil) ⇒ Object
Show help.
-
#print_eval_error(e) ⇒ Object
When printing error, cut backtrace at (ripl).
-
#print_result(result) ⇒ Object
Don’t print nil return values.
Class Method Details
.run(instance, opts = {}) ⇒ Object
Run the Ripl shell in context of specified instance
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/resque/pool/dynamic/shell.rb', line 80 def self.run(instance, opts={}) = { :readline => true, :riplrc => ENV['RIPL_RC'] || '~/.riplrc', :completion => {}, :binding => instance.instance_eval { binding } } .update(opts) Ripl::Runner::load_rc([:riplrc]) if [:riplrc]!='' create().loop end |
Instance Method Details
#eval_input(input) ⇒ Object
Handle help as special command
68 69 70 71 72 73 74 75 |
# File 'lib/resque/pool/dynamic/shell.rb', line 68 def eval_input(input) splut = input.split(/\s+/,2) if splut.first == 'help' help(splut[1]) else super end end |
#help(subject = nil) ⇒ Object
Show help
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/resque/pool/dynamic/shell.rb', line 48 def help(subject=nil) @help ||= File.open( Pathname.new(__FILE__).dirname.join('help.json') ) { |f| JSON::load(f.read) } if subject if @help.has_key?(subject) puts @help[subject]['full'] return end puts "I don't know anything about #{subject}." end puts "Known commands:" @help.keys.sort.each do |cmd| puts " #{cmd} - #{@help[cmd]['summary']}" end puts "For details, type: help command" end |
#print_eval_error(e) ⇒ Object
When printing error, cut backtrace at (ripl)
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/resque/pool/dynamic/shell.rb', line 28 def print_eval_error(e) i = e.backtrace.index { |ln| ln =~ /\(ripl\):\d+:in `run'/ } if not i bt = e.backtrace elsif i > 0 bt = e.backtrace[0..i-1] else bt = [] end bt = bt.map { |ln| " " << ln }.join("\n") puts "ERROR: #{e.to_s}\n#{bt}" end |
#print_result(result) ⇒ Object
Don’t print nil return values
42 43 44 |
# File 'lib/resque/pool/dynamic/shell.rb', line 42 def print_result(result) super if @error_raised or !result.nil? end |