Class: RedshiftConnector::AbstractDataFile

Inherits:
Object
  • Object
show all
Defined in:
lib/redshift_connector/abstract_data_file.rb

Direct Known Subclasses

S3DataFile, UrlDataFile

Instance Method Summary collapse

Constructor Details

#initialize(reader_class:) ⇒ AbstractDataFile

Returns a new instance of AbstractDataFile.



5
6
7
# File 'lib/redshift_connector/abstract_data_file.rb', line 5

def initialize(reader_class:)
  @reader_class = reader_class
end

Instance Method Details

#data_object?Boolean

abstract open

Returns:

  • (Boolean)


23
24
25
# File 'lib/redshift_connector/abstract_data_file.rb', line 23

def data_object?
  @reader_class.data_object?(key)
end

#each_row(&block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/redshift_connector/abstract_data_file.rb', line 9

def each_row(&block)
  f = open
  begin
    if gzipped_object?
      f = Zlib::GzipReader.new(f)
    end
    @reader_class.new(f).each(&block)
  ensure
    f.close
  end
end

#gzipped_object?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/redshift_connector/abstract_data_file.rb', line 27

def gzipped_object?
  File.extname(key) == '.gz'
end