Class: JRubySQL::Input::Console
- Inherits:
-
Object
- Object
- JRubySQL::Input::Console
- Defined in:
- lib/jrubysql/input/console.rb
Instance Method Summary collapse
- #delimiter ⇒ Object
- #delimiter=(delim) ⇒ Object
- #get ⇒ Object
-
#initialize(controller) ⇒ Console
constructor
A new instance of Console.
- #prepare(sqls) ⇒ Object
Constructor Details
#initialize(controller) ⇒ Console
Returns a new instance of Console.
6 7 8 9 |
# File 'lib/jrubysql/input/console.rb', line 6 def initialize controller @controller = controller @esql = JRubySQL::Input.get_parser @controller.db_type end |
Instance Method Details
#delimiter ⇒ Object
49 50 51 |
# File 'lib/jrubysql/input/console.rb', line 49 def delimiter @esql.delimiter end |
#delimiter=(delim) ⇒ Object
53 54 55 |
# File 'lib/jrubysql/input/console.rb', line 53 def delimiter= delim @esql.delimiter = delim end |
#get ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jrubysql/input/console.rb', line 17 def get empty_response = { :sqls => [], :commands => [] } line = Readline::readline(@controller.cursor(@esql.empty?), false) return( # CTRL-D if line.nil? puts @esql.clear empty_response # Empty input (not inside a block) elsif @esql.empty? && line.gsub(/\s/m, '').empty? empty_response # Console commands elsif @esql.empty? && cmd = process_command(line) { :commands => [cmd, line] } # Line with delimiters elsif line.include?(@esql.delimiter) @esql << line + $/ result = @esql.shift result[:sqls].each do |sql| Readline::HISTORY << sql + @esql.delimiter end { :sqls => result[:sqls], :delimiter => @esql.delimiter, :history => true } # SQL without delimiter else @esql << line + $/ empty_response end ) end |
#prepare(sqls) ⇒ Object
11 12 13 14 15 |
# File 'lib/jrubysql/input/console.rb', line 11 def prepare sqls sqls.each do |sql| Readline::HISTORY << sql end end |