Sha256: 9e16618632ba7a99105d21321fc82ba1ac31cc6bc3642b693520222f7f543de3

Contents?: true

Size: 744 Bytes

Versions: 3

Compression:

Stored size: 744 Bytes

Contents

class Realogy::Entity < ApplicationRecord
  self.table_name = 'realogy_entities'

  validates :type, presence: true
  validates :entity_id, presence: true
  validates :last_update_on, presence: true

  def needs_updating?
    self.new_record? || self.last_update_on_changed? || self.data.blank?
  end

  def self.triage hash
    @object = self.find_or_initialize_by(entity_id: [hash["entityId"], hash["id"]].compact.first)
    @object.last_update_on = hash["lastUpdateOn"]
    @object.populate if @object.needs_updating?
  end
  
  def populate
    call = ["get_", self.class.to_s.downcase.split("::").last, "_by_id"].join.to_sym
    self.data = Realogy::DataSync.client.__send__(call, self.entity_id)
    self.save if self.changed?
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
realogy-0.3.1 lib/realogy/app/models/realogy/entity.rb
realogy-0.3.0 lib/realogy/app/models/realogy/entity.rb
realogy-0.2.0 lib/realogy/app/models/realogy/entity.rb