Class: CSVModel::RowActiveRecordAdaptor

Inherits:
SimpleDelegator
  • Object
show all
Includes:
RecordStatus
Defined in:
lib/csv_model/row_active_record_adaptor.rb

Constant Summary

Constants included from RecordStatus

CSVModel::RecordStatus::CREATE, CSVModel::RecordStatus::DELETE, CSVModel::RecordStatus::DUPLICATE, CSVModel::RecordStatus::ERROR_ON_CREATE, CSVModel::RecordStatus::ERROR_ON_DELETE, CSVModel::RecordStatus::ERROR_ON_READ, CSVModel::RecordStatus::ERROR_ON_UPDATE, CSVModel::RecordStatus::NOT_CHANGED, CSVModel::RecordStatus::UNKNOWN, CSVModel::RecordStatus::UPDATE

Instance Method Summary collapse

Instance Method Details

#assign_attributes(attributes) ⇒ Object



7
8
9
# File 'lib/csv_model/row_active_record_adaptor.rb', line 7

def assign_attributes(attributes)
  __getobj__.try(:assign_attributes, attributes)
end

#errorsObject



11
12
13
14
15
16
17
18
# File 'lib/csv_model/row_active_record_adaptor.rb', line 11

def errors
  if __getobj__.nil?
    ["Record could not be created or updated"]
  else
    value = __getobj__.errors
    value.try(:full_messages) || value
  end
end

#mark_as_duplicateObject



20
21
22
# File 'lib/csv_model/row_active_record_adaptor.rb', line 20

def mark_as_duplicate
  @is_duplicate = true
end

#save(options = {}) ⇒ Object



24
25
26
27
# File 'lib/csv_model/row_active_record_adaptor.rb', line 24

def save(options = {})
  capture_state(options[:dry_run])
  @was_saved = was_editable? && was_valid? && (is_dry_run? || save_or_destroy)
end

#statusObject



29
30
31
32
33
34
35
# File 'lib/csv_model/row_active_record_adaptor.rb', line 29

def status
  return ERROR_ON_READ if __getobj__.nil?
  return DUPLICATE if is_dry_run? && is_duplicate?
  return status_for_new_record if was_new?
  return status_for_existing_record if was_existing?
  UNKNOWN
end

#valid?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/csv_model/row_active_record_adaptor.rb', line 37

def valid?
  __getobj__.try(:valid?)
end