Class: Apiphobic::Middleware::Validators::Subdomain

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/apiphobic/middleware/validators/subdomain.rb

Instance Method Summary collapse

Methods included from Configurable

#configuration, included

Constructor Details

#initialize(app) ⇒ Subdomain

Returns a new instance of Subdomain.



13
14
15
# File 'lib/apiphobic/middleware/validators/subdomain.rb', line 13

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/apiphobic/middleware/validators/subdomain.rb', line 17

def call(env)
  request   = Requests::Subdomain.new(env)
  subdomain = Matchers::Subdomain.new(
                allowed_subdomains: configuration.allowed_subdomains,
              )

  return Responses::InvalidSubdomain.call(env) unless subdomain.matches?(request)

  @app.call(env)
end