Class: IncomingDomain

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/incoming_domain.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add!(uri) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/incoming_domain.rb', line 4

def self.add!(uri)
  name = uri.host
  return unless name.present?

  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)
  rescue ActiveRecord::RecordNotUnique
    # duplicate key is just ignored
  end

  current || find_by(name: name, https: https, port: port)
end

Instance Method Details

#to_urlObject



25
26
27
28
29
30
31
# File 'app/models/incoming_domain.rb', line 25

def to_url
  url = +"http#{https ? "s" : ""}://#{name}"

  url << ":#{port}" if https && port != 443 || !https && port != 80

  url
end