Class: Metacrunch::File::FileDestination
- Inherits:
-
Object
- Object
- Metacrunch::File::FileDestination
- Defined in:
- lib/metacrunch/file/file_destination.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_OPTIONS =
{ override_existing_file: false }
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(filename, options = {}) ⇒ FileDestination
constructor
A new instance of FileDestination.
- #write(data) ⇒ Object
Constructor Details
#initialize(filename, options = {}) ⇒ FileDestination
Returns a new instance of FileDestination.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/metacrunch/file/file_destination.rb', line 10 def initialize(filename, = {}) @filename = ::File.(filename) @options = DEFAULT_OPTIONS.deep_merge() if ::File.exists?(@filename) && @options[:override_existing_file] == false raise "File `#{@filename}` exists but `override_existing_file` option was set to `false`" end @file = ::File.open(@filename, 'wb+') end |
Instance Method Details
#close ⇒ Object
31 32 33 |
# File 'lib/metacrunch/file/file_destination.rb', line 31 def close @file.close if @file end |
#write(data) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/metacrunch/file/file_destination.rb', line 21 def write(data) return if data.blank? if data.is_a?(Array) data.each { |row| @file.write(row) } else @file.write(data) end end |