Module: RedashExporter::Exporter
- Defined in:
- lib/redash_exporter/exporter.rb
Class Method Summary collapse
-
.export(file_path, content, option = {}) ⇒ Object
Export a file.
- .should_overwrite?(path, option = {}) ⇒ Boolean
Class Method Details
.export(file_path, content, option = {}) ⇒ Object
Export a file.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/redash_exporter/exporter.rb', line 12 def export(file_path, content, option = {}) unless should_overwrite?(file_path, option) puts "Not create #{file_path}." return end File.open(file_path, 'w') do |file| file.print content end end |
.should_overwrite?(path, option = {}) ⇒ Boolean
23 24 25 26 27 28 29 30 31 |
# File 'lib/redash_exporter/exporter.rb', line 23 def should_overwrite?(path, option = {}) return true if option[:force] return true unless File.exist?(path) puts "Overwrite #{path}? [yes(y), no(n)]" should_overwrite = %w[yes y].include?(STDIN.gets.strip) should_overwrite end |