discourse/app/models/incoming_domain.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1016 B
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
2014-08-03 22:35:55 -04:00
class IncomingDomain < ActiveRecord::Base
def self.add!(uri)
name = uri.host
return if name.blank?
https = uri.scheme == "https"
port = uri.port
current = find_by(name: name, https: https, port: port)
return current if current
# concurrency ...
begin
current = create!(name: name, https: https, port: port)
2014-08-05 20:00:43 -04:00
rescue ActiveRecord::RecordNotUnique
# duplicate key is just ignored
end
current || find_by(name: name, https: https, port: port)
end
def to_url
url = +"http#{https ? "s" : ""}://#{name}"
url << ":#{port}" if https && port != 443 || !https && port != 80
url
end
2014-08-03 22:35:55 -04:00
end
# == Schema Information
#
# Table name: incoming_domains
#
# id :integer not null, primary key
# name :string(100) not null
# https :boolean default(FALSE), not null
# port :integer not null
#
# Indexes
#
# index_incoming_domains_on_name_and_https_and_port (name,https,port) UNIQUE
#