Sha256: 9a9241f708a859d0ae5f6c490f62f2493d5f833e59d6437f6a1deb9623d1303a

Contents?: true

Size: 675 Bytes

Versions: 1

Compression:

Stored size: 675 Bytes

Contents

class Import < ActiveRecord::Base

  belongs_to :import_format

  has_many :listings
  has_many :queued_listings
  
  validates_uniqueness_of :token

  before_save :set_import_format

  def remove_listings_no_longer_present fresh_listing_keys
    existing_listing_keys = self.listings.all.pluck(:listing_key)
    stale_listing_keys = existing_listing_keys.delete_if{|key| fresh_listing_keys.include? key }
    stale_listing_keys.each do |listing_key|
      Listing.find_by(listing_key: listing_key).destroy
    end
    stale_listing_keys
  end

  def set_import_format
    self.import_format = ImportFormat.find_by(name: 'reso') unless self.import_format.present?
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reso-0.1.1.0 app/models/import.rb