class CSVModel::RowActiveRecordAdaptor
Public Instance Methods
assign_attributes(attributes)
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 7 def assign_attributes(attributes) __getobj__.try(:assign_attributes, attributes) end
errors()
click to toggle source
# 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_duplicate()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 20 def mark_as_duplicate @is_duplicate = true end
save(options = {})
click to toggle source
# 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
status()
click to toggle source
# 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?()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 37 def valid? __getobj__.try(:valid?) end
Private Instance Methods
capture_state(dry_run)
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 43 def capture_state(dry_run) @is_dry_run = dry_run == true if !__getobj__.nil? @was_changed = changed? @was_deleted = marked_for_destruction? @was_editable = __getobj__.respond_to?(:editable?) ? __getobj__.editable? : true @was_new = new_record? @was_valid = valid? end end
is_dry_run?()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 58 def is_dry_run? @is_dry_run end
is_duplicate?()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 54 def is_duplicate? @is_duplicate end
save_or_destroy()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 62 def save_or_destroy if marked_for_destruction? __getobj__.destroy if persisted? else __getobj__.save end end
status_for_existing_record()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 70 def status_for_existing_record return DELETE if was_deleted? return NOT_CHANGED if !was_changed? return UPDATE if was_valid? && was_saved? ERROR_ON_UPDATE # if (!was_editable? || !was_valid? || !was_saved?) end
status_for_new_record()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 77 def status_for_new_record return ERROR_ON_DELETE if was_deleted? return ERROR_ON_CREATE if was_not_valid? CREATE # if valid? end
was_changed?()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 83 def was_changed? @was_changed end
was_deleted?()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 87 def was_deleted? @was_deleted end
was_editable?()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 91 def was_editable? @was_editable end
was_existing?()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 95 def was_existing? !was_new? end
was_new?()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 99 def was_new? @was_new end
was_not_valid?()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 107 def was_not_valid? !was_valid? end
was_saved?()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 103 def was_saved? @was_saved end
was_valid?()
click to toggle source
# File lib/csv_model/row_active_record_adaptor.rb, line 111 def was_valid? @was_valid end