class Rack::IpRestrictor::Config

Configuration class for the IpRestrictor @example

Rack::IpRestrictor.configure do
  respond_with [403, {'Content-Type' => 'text/html'}, '']

  ips_for :test do
    add '127.0.0.1'
    add '127.0.0.2/8'
  end

  restrict /^\/admin/, '/admin', :only => :test
end

@see README.rdoc

Attributes

ip_groups[RW]
response[RW]
restrictions[RW]

Public Class Methods

new() click to toggle source
# File lib/rack_ip_restrictor/config.rb, line 18
def initialize
  @ip_groups = {}
  @restrictions = []
  @response = [
    403,
    {'Content-Type' => 'text/html'},
    ''
  ]
end

Public Instance Methods

ips_for(name, &block) click to toggle source

Sets and gets IP addresses for a named group

@return [IpGroup] IP addresses for a named group

# File lib/rack_ip_restrictor/config.rb, line 38
def ips_for(name, &block)
  if block_given?
    @ip_groups[name] = IpGroup.new
    @ip_groups[name].instance_eval &block
    @ip_groups[name]
  else
    @ip_groups[name]
  end
end
respond_with(response) click to toggle source

Overwrites the default response. Same format as a middleware response.

@param [Array<Integer, String, String>] response status, a set of headers, body

# File lib/rack_ip_restrictor/config.rb, line 31
def respond_with(response)
  @response = response
end
restrict(*args) click to toggle source

Adds a restriction @see Restriction#initialize

# File lib/rack_ip_restrictor/config.rb, line 50
def restrict(*args)
  @restrictions << Restriction.new(*args)
end