Class: Bricolage::TDTask::Export
- Inherits:
-
Action
- Object
- Action
- Bricolage::TDTask::Export
show all
- Includes:
- CommandUtils
- Defined in:
- lib/bricolage/tddatasource.rb
Constant Summary
collapse
- GZIP_COMMAND =
'gzip'
Instance Method Summary
collapse
#command, #make_tmpfile, #new_tmpfile_path, #retrieve_last_match_from_stderr
Constructor Details
#initialize(stmt, path: nil, format: nil, gzip: false, override: false) ⇒ Export
Returns a new instance of Export.
45
46
47
48
49
50
51
|
# 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
|
Instance Method Details
#command_args(query_path) ⇒ Object
80
81
82
|
# 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 ⇒ Object
84
85
86
|
# File 'lib/bricolage/tddatasource.rb', line 84
def export_path
@gzip ? @path.sub(/\.gz\z/, '') : @path
end
|
#run ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# 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 ⇒ Object
55
56
57
58
59
60
61
|
# 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
|