Class: DataShift::CsvGenerator

Inherits:
GeneratorBase show all
Defined in:
lib/datashift/generators/csv_generator.rb

Instance Attribute Summary collapse

Attributes inherited from GeneratorBase

#configuration

Instance Method Summary collapse

Methods inherited from GeneratorBase

#generate_with_associations

Methods included from Logging

#logdir, #logdir=, #logger, #verbose

Constructor Details

#initializeCsvGenerator

Returns a new instance of CsvGenerator.



14
15
16
# File 'lib/datashift/generators/csv_generator.rb', line 14

def initialize
  super
end

Instance Attribute Details

#file_nameObject

Returns the value of attribute file_name.



12
13
14
# File 'lib/datashift/generators/csv_generator.rb', line 12

def file_name
  @file_name
end

Instance Method Details

#generate(file_name, klass) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/datashift/generators/csv_generator.rb', line 18

def generate(file_name, klass)
  @file_name = file_name

  headers = Headers.klass_to_headers(klass)

  logger.info("CSVGenerator saving generated Template #{@file_name}")

  csv_delim = DataShift::Exporters::Configuration.call.csv_delimiter

  CSV.open(file_name, 'w', col_sep: csv_delim ) do |csv|
    csv << headers.sources
  end

end