Class: Rack::IpAddressRestriction

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/ip_address_restriction.rb,
lib/rack/ip_address_restriction/version.rb

Constant Summary collapse

VERSION =
"0.1.2"

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ IpAddressRestriction

Returns a new instance of IpAddressRestriction.



11
12
13
14
15
# File 'lib/rack/ip_address_restriction.rb', line 11

def initialize(app, options = {})
  @app = app
  options = DEFAULT_MAPPING if options.empty?
  @mapping = create_mapping(options)
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/rack/ip_address_restriction.rb', line 17

def call(env)
  if allow?(env)
    @app.call(env)
  else
    [403, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
  end
end