Class: Simplec::Subdomains

Inherits:
Object
  • Object
show all
Defined in:
app/constraints/simplec/subdomains.rb

Class Method Summary collapse

Class Method Details

.matches?(request) ⇒ Boolean

Returns:

  • (Boolean)

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/constraints/simplec/subdomains.rb', line 3

def self.matches?(request)
  simplec = request.headers['HTTP_X_ENGINE'] == 'simplec'
  present = request.subdomain.present?
  not_admin = request.subdomain != 'admin'
  subdomain = Simplec::Subdomain.find_by(name: request.subdomain)

  match = simplec || (present && not_admin && subdomain)

  if match
    Thread.current[:simplec_subdomain] = subdomain
    Rails.logger.info <<-LOG
Simplec request received.
  ActionDispatch::Request#original_url: #{request.original_url}
  Simplec Engine: #{not_admin}
  LOG
  else
    Rails.logger.info <<-LOG
Simplec Subdomain '#{request.subdomain}' was not found.
  ActionDispatch::Request#original_url: #{request.original_url}
  'admin' subdomain bypass: #{!not_admin}
  LOG
  end

  match
end