class Turnout::Request

Attributes

rack_request[R]

Public Class Methods

new(env) click to toggle source
# File lib/turnout/request.rb, line 5
def initialize(env)
  @rack_request = Rack::Request.new(env)
end

Public Instance Methods

allowed?(settings) click to toggle source
# File lib/turnout/request.rb, line 9
def allowed?(settings)
  path_allowed?(settings.allowed_paths) || ip_allowed?(settings.allowed_ips)
end

Private Instance Methods

ip_allowed?(allowed_ips) click to toggle source
# File lib/turnout/request.rb, line 23
def ip_allowed?(allowed_ips)
  begin
    ip = IPAddr.new(rack_request.ip.to_s)
  rescue ArgumentError
    return false
  end

  allowed_ips.any? do |allowed_ip|
    IPAddr.new(allowed_ip).include? ip
  end
end
path_allowed?(allowed_paths) click to toggle source
# File lib/turnout/request.rb, line 17
def path_allowed?(allowed_paths)
  allowed_paths.any? do |allowed_path|
    rack_request.path =~ Regexp.new(allowed_path)
  end
end