Class: EacRailsRemotes::Instance

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/eac_rails_remotes/instance.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.import(record) ⇒ Object



68
69
70
71
72
73
74
75
# File 'app/models/eac_rails_remotes/instance.rb', line 68

def import(record)
  ri = where(source: record[:source], entity: record[:entity], code: record[:code])
         .first_or_initialize
  ri.data = record[:data].to_yaml
  ri.export_status = EXPORT_STATUS_NEW_DATA
  ri.save!
  ri
end

Instance Method Details

#exportObject



27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/eac_rails_remotes/instance.rb', line 27

def export
  Rails.logger.info("Exporting #{self}")
  t = target || entity_class.new
  t.attributes = target_attributes
  if t.save
    update!(export_status: EXPORT_STATUS_OK, export_message: '', target: t)
  else
    update!(export_status: EXPORT_STATUS_ERROR,
            export_message: target_export_message(t))
  end
end

#to_sObject



23
24
25
# File 'app/models/eac_rails_remotes/instance.rb', line 23

def to_s
  "#{source}|#{entity}|#{code}"
end