class Metacrunch::File::FileDestination

Constants

DEFAULT_OPTIONS

Public Class Methods

new(filename, options = {}) click to toggle source
# File lib/metacrunch/file/file_destination.rb, line 10
def initialize(filename, options = {})
  @filename = ::File.expand_path(filename)
  @options = DEFAULT_OPTIONS.deep_merge(options)

  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

Public Instance Methods

close() click to toggle source
# File lib/metacrunch/file/file_destination.rb, line 31
def close
  @file.close if @file
end
write(data) click to toggle source
# 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