Class: Drudgery::Loaders::ActiveRecordImportLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/drudgery/loaders/active_record_import_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ ActiveRecordImportLoader

Returns a new instance of ActiveRecordImportLoader.



6
7
8
9
# File 'lib/drudgery/loaders/active_record_import_loader.rb', line 6

def initialize(model)
  @model = model
  @name = "active_record_import:#{@model.name}"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/drudgery/loaders/active_record_import_loader.rb', line 4

def name
  @name
end

Instance Method Details

#load(records) ⇒ Object



11
12
13
14
15
16
# File 'lib/drudgery/loaders/active_record_import_loader.rb', line 11

def load(records)
  columns = records.first.keys
  values = records.map { |record| columns.map { |column| record[column] } }

  @model.import(columns, values, :validate => false)
end