module CsvRecord::Writer::ClassMethods

Public Instance Methods

__create__(attributes={}) { |instance| ... } click to toggle source
# File lib/csv_record/writer.rb, line 5
def __create__(attributes={})
  build(attributes).tap do |instance|
    yield instance if block_given?
    instance.save
  end
end
Also aliased as: create
create(attributes={})
Alias for: __create__
mapping(config=[]) click to toggle source
# File lib/csv_record/writer.rb, line 34
def mapping(config=[])
  config.each do |field, doppelganger|
    unless fields.include? field
      fields << CsvRecord::Field.new(field, doppelganger)
    end
  end
end
redefine_database_location() click to toggle source
# File lib/csv_record/writer.rb, line 42
def redefine_database_location
  if const_defined?('DATABASE_LOCATION') || const_defined?('DATABASE_LOCATION_TMP')
    send :remove_const, 'DATABASE_LOCATION'
    send :remove_const, 'DATABASE_LOCATION_TMP'
  end

  const_set 'DATABASE_LOCATION', "db/#{@table_name}.csv"
  const_set 'DATABASE_LOCATION_TMP', "db/#{@table_name}_tmp.csv"
end
store_as(name) click to toggle source
# File lib/csv_record/writer.rb, line 23
def store_as(name)
  @table_name = name.to_s.underscore.pluralize
  redefine_database_location

  @table_name
end
table_name() click to toggle source
# File lib/csv_record/writer.rb, line 30
def table_name
  @table_name ||= store_as name
end