class Bricolage::TDTask::Export

Constants

GZIP_COMMAND

Public Class Methods

new(stmt, path: nil, format: nil, gzip: false, override: false) click to toggle source
# File lib/bricolage/tddatasource.rb, line 45
def initialize(stmt, path: nil, format: nil, gzip: false, override: false)
  @statement = stmt
  @path = path
  @format = format
  @gzip = gzip
  @override = override
end

Public Instance Methods

command_args(query_path) click to toggle source
# File lib/bricolage/tddatasource.rb, line 80
def command_args(query_path)
  ds.query_command_args("--query=#{query_path}", "--output=#{export_path}", "--format=#{@format}")
end
export_path() click to toggle source
# File lib/bricolage/tddatasource.rb, line 84
def export_path
  @gzip ? @path.sub(/\.gz\z/, '') : @path
end
run() click to toggle source
# File lib/bricolage/tddatasource.rb, line 65
def run
  if File.exist?(@path) and not @override
    raise JobFailure, "target file exists: #{@path.inspect}"
  end
  puts @statement.source
  td_result = make_tmpfile(@statement.stripped_source) {|query_path|
    ds.exec(*command_args(query_path))
  }
  if @gzip
    gzip_result = ds.command(GZIP_COMMAND, export_path)
    raise JobFailure, "gzip failed" unless gzip_result.success?
  end
  td_result
end
source() click to toggle source
# File lib/bricolage/tddatasource.rb, line 55
def source
  buf = StringIO.new
  buf.puts command_args(new_tmpfile_path).join(' ') + " <<EndTDSQL"
  buf.puts @statement.stripped_source
  buf.puts 'EndTDSQL'
  buf.string
end