Class: Baza::Commands::Importer
- Inherits:
-
Object
- Object
- Baza::Commands::Importer
- Defined in:
- lib/baza/commands/importer.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(args) ⇒ Importer
constructor
A new instance of Importer.
Constructor Details
#initialize(args) ⇒ Importer
Returns a new instance of Importer.
2 3 4 5 6 |
# File 'lib/baza/commands/importer.rb', line 2 def initialize(args) @db = args.fetch(:db) @debug = args[:debug] @io = args.fetch(:io) end |
Instance Method Details
#execute ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/baza/commands/importer.rb', line 8 def execute sql = "" @io.each_line do |line| next if line.strip.blank? next if line.start_with?("--") debug "Add line to SQL: #{line}" if @debug sql << line next unless line.end_with?(";\n") debug "Execute SQL: #{sql}" if @debug @db.query(sql) sql = "" end end |