module CsvRecord::Writer::InstanceMethods

Public Class Methods

included(receiver) click to toggle source
# File lib/csv_record/writer.rb, line 56
def self.included(receiver)
  receiver.send :attr_accessor, :id
end

Public Instance Methods

__destroy__() click to toggle source
# File lib/csv_record/writer.rb, line 89
def __destroy__
  self.class.parse_database_file do |row|
    new_row = row
    new_row = nil if id.to_i == row.field('id').to_i
    new_row
  end
  empty_fields
  true
end
Also aliased as: destroy
__save__(validate=true) click to toggle source
# File lib/csv_record/writer.rb, line 60
def __save__(validate=true)
  if (not validate) || valid?
    new_record? ? append_registry : update_registry
  else
    false
  end
end
Also aliased as: save
__update_attribute__(field, value) click to toggle source
# File lib/csv_record/writer.rb, line 72
def __update_attribute__(field, value)
  public_send "#{field}=", value
  save false
end
Also aliased as: update_attribute
__update_attributes__(params={validate: true}) { |self| ... } click to toggle source
# File lib/csv_record/writer.rb, line 77
def __update_attributes__(params={validate: true})
  validate = params.delete :validate

  params.each do |field, value|
    public_send "#{field}=", value
  end

  yield self if block_given?

  save validate
end
Also aliased as: update_attributes
new_record?() click to toggle source
# File lib/csv_record/writer.rb, line 68
def new_record?
  created_at.nil? || id.nil?
end

Private Instance Methods

__write_object__() click to toggle source
# File lib/csv_record/writer.rb, line 118
def __write_object__
  calculate_id
  self.class.open_database_file CsvRecord::Connector::APPEND_MODE do |csv|
    csv << values
  end
  true
end
Also aliased as: write_object
append_registry() click to toggle source
# File lib/csv_record/writer.rb, line 105
def append_registry
  write_object
end
calculate_id() click to toggle source
# File lib/csv_record/writer.rb, line 101
def calculate_id
  @id = self.class.count + 1
end
destroy()
Alias for: __destroy__
empty_fields() click to toggle source
# File lib/csv_record/writer.rb, line 126
def empty_fields
  %w(id created_at updated_at).each do |field|
    public_send "#{field}=", nil
  end
end
save(validate=true)
Alias for: __save__
update_attribute(field, value)
update_attributes(params={validate: true})
update_registry() click to toggle source
# File lib/csv_record/writer.rb, line 109
def update_registry
  self.class.parse_database_file do |row|
    new_row = row
    new_row = values if id.to_i == row.field('id').to_i
    new_row
  end
  true
end
write_object()
Alias for: __write_object__