Class: ActiveRecordCopy::CopyFromClient::CopyHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord-copy.rb

Instance Method Summary collapse

Constructor Details

#initialize(columns:, model_class:, table_name:) ⇒ CopyHandler

Returns a new instance of CopyHandler.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/activerecord-copy.rb', line 19

def initialize(columns:, model_class:, table_name:)
  @columns      = columns
  @model_class  = model_class
  @connection   = model_class.connection.raw_connection
  @table_name   = table_name
  @column_types = columns.map do |c|
    column = model_class.columns_hash[c.to_s]
    raise format('Could not find column %s on %s', c, model_class.table_name) if column.nil?

    if column.type == :integer
      if column.limit == 8
        :bigint
      elsif column.limit == 2
        :smallint
      else
        :integer
      end
    else
      column.type
    end
  end

  reset
end

Instance Method Details

#<<(row) ⇒ Object



44
45
46
# File 'lib/activerecord-copy.rb', line 44

def <<(row)
  @encoder.add row
end

#closeObject



48
49
50
# File 'lib/activerecord-copy.rb', line 48

def close
  run_copy
end