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


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 "Simplec request received.\nActionDispatch::Request#original_url: \#{request.original_url}\nSimplec Engine: \#{not_admin}\n"
  else
    Rails.logger.info "Simplec Subdomain '\#{request.subdomain}' was not found.\nActionDispatch::Request#original_url: \#{request.original_url}\n'admin' subdomain bypass: \#{!not_admin}\n"
  end

  match
end