Sha256: 330d9ee08dd962ab1c7e3066050917a54d6533a4bd2099a5301ac94acbe40444

Contents?: true

Size: 884 Bytes

Versions: 30

Compression:

Stored size: 884 Bytes

Contents

class QueuedListing < ActiveRecord::Base
  belongs_to :import
  serialize :listing_data
  after_save :create_listing_and_remove_myself

  def mapper
    "Mapper::#{self.import.import_format.name.downcase.capitalize}".constantize
  end

  def create_or_update_listing
    listing = self.import.listings.
      eager_load(:address).
      eager_load(:appliances).
      eager_load(:participants).
      eager_load(:photos).
      find_or_initialize_by(
        listing_key: Mapper::unique_identifier(self)
      )
    if (listing.modification_timestamp != mapper.modification_timestamp(self, listing))
      Mapper::RESO_LISTING_ATTRIBUTES.each do |attribute|
        listing.send("#{attribute}=", mapper.send(attribute, self, listing))
      end
      listing.save
    end
  end

  def create_listing_and_remove_myself
    create_or_update_listing ? self.destroy : false 
  end
  
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
reso-0.1.6.7 app/models/queued_listing.rb
reso-0.1.6.6 app/models/queued_listing.rb
reso-0.1.6.5 app/models/queued_listing.rb
reso-0.1.6.4 app/models/queued_listing.rb
reso-0.1.5.11 app/models/queued_listing.rb
reso-0.1.5.10 app/models/queued_listing.rb
reso-0.1.5.9 app/models/queued_listing.rb
reso-0.1.5.7 app/models/queued_listing.rb
reso-0.1.5.6 app/models/queued_listing.rb
reso-0.1.5.5 app/models/queued_listing.rb
reso-0.1.5.4 app/models/queued_listing.rb
reso-0.1.5.3 app/models/queued_listing.rb
reso-0.1.5.2 app/models/queued_listing.rb
reso-0.1.5.1 app/models/queued_listing.rb
reso-0.1.5.0 app/models/queued_listing.rb
reso-0.1.4.10 app/models/queued_listing.rb
reso-0.1.4.9 app/models/queued_listing.rb
reso-0.1.4.8 app/models/queued_listing.rb
reso-0.1.4.7 app/models/queued_listing.rb
reso-0.1.4.6 app/models/queued_listing.rb