Class: ActiveRecord::Acts::Partitioned::CopyFile

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/acts/partitioned/copy_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(table_name, options = {}) ⇒ CopyFile

Returns a new instance of CopyFile.



52
53
54
55
56
57
58
59
# File 'lib/active_record/acts/partitioned/copy_proxy.rb', line 52

def initialize(table_name, options = {})
  @table_name = table_name
  @options = options
  @header_written = false
  @filename = generate_filename
  @file = File.open(::COPY_FILE_DIRECTORY + @filename, "w")
  #write_meta
end

Instance Method Details

#<<(hash) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/active_record/acts/partitioned/copy_proxy.rb', line 61

def <<(hash)
  unless @header_written
    write_header(hash.keys)
  end
  # TODO: Write values
  @file << hash.values.map { |v| quote_and_escape(v) }.join(',') << "\n"
end

#closeObject



69
70
71
# File 'lib/active_record/acts/partitioned/copy_proxy.rb', line 69

def close
  @file.close
end