Class: ActiveAccess::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/active-access/middleware.rb

Constant Summary collapse

WHITELISTED_IPS =
Set.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, handler = {}) ⇒ Middleware

Returns a new instance of Middleware.



15
16
17
18
19
# File 'lib/active-access/middleware.rb', line 15

def initialize(app, handler = {})
  @app             = app
  @handler         = handler
  refresh_whitelisted_ips
end

Class Method Details

.allow_ip!(addr) ⇒ Object



11
12
13
# File 'lib/active-access/middleware.rb', line 11

def self.allow_ip!(addr)
  WHITELISTED_IPS << IPAddr.new(addr)
end

Instance Method Details

#call(rack_request) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/active-access/middleware.rb', line 21

def call(rack_request)
  if allow?(rack_request)
    @app.call(rack_request)
  else
    [404, { "Content-Type" => "text/html", "Content-Length" => config.message.length.to_s }, [config.message]]
  end
end