2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-08-03 22:35:55 -04:00
|
|
|
class IncomingReferer < ActiveRecord::Base
|
2014-08-04 02:43:57 -04:00
|
|
|
belongs_to :incoming_domain
|
|
|
|
|
|
|
|
def self.add!(opts)
|
|
|
|
domain_id = opts[:incoming_domain_id]
|
|
|
|
domain_id ||= opts[:incoming_domain].id
|
|
|
|
path = opts[:path]
|
|
|
|
|
|
|
|
current = find_by(path: path, incoming_domain_id: domain_id)
|
|
|
|
return current if current
|
|
|
|
|
|
|
|
begin
|
|
|
|
current = create!(path: path, incoming_domain_id: domain_id)
|
2014-08-05 20:00:43 -04:00
|
|
|
rescue ActiveRecord::RecordNotUnique
|
|
|
|
# does not matter
|
2014-08-04 02:43:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
current || find_by(path: path, incoming_domain_id: domain_id)
|
|
|
|
end
|
2014-08-03 22:35:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: incoming_referers
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# path :string(1000) not null
|
|
|
|
# incoming_domain_id :integer not null
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_incoming_referers_on_path_and_incoming_domain_id (path,incoming_domain_id) UNIQUE
|
|
|
|
#
|