Class: DbSeeder::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/db_seeder/exporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, config) ⇒ Exporter

Returns a new instance of Exporter.



7
8
9
10
# File 'lib/db_seeder/exporter.rb', line 7

def initialize(model, config)
  @model = model
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/db_seeder/exporter.rb', line 5

def config
  @config
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/db_seeder/exporter.rb', line 5

def model
  @model
end

Instance Method Details

#exportObject



12
13
14
15
16
17
18
# File 'lib/db_seeder/exporter.rb', line 12

def export
  records = []
  model.find_in_batches(batch_size: config.batch_size) do |batch|
    records.concat(batch.map(&method(:serialize_record)))
  end
  records
end