Class: Drudgery::Loaders::ActiveRecordImportLoader
- Inherits:
-
Object
- Object
- Drudgery::Loaders::ActiveRecordImportLoader
- Defined in:
- lib/drudgery/loaders/active_record_import_loader.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(model) ⇒ ActiveRecordImportLoader
constructor
A new instance of ActiveRecordImportLoader.
- #load(records) ⇒ Object
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
#name ⇒ Object (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 |