Class: Rack::IpRestrictor::Restriction
- Inherits:
-
Object
- Object
- Rack::IpRestrictor::Restriction
- Defined in:
- lib/rack_ip_restrictor/restriction.rb
Overview
Handles restrictions
Instance Method Summary (collapse)
-
- (Restriction) initialize(*args)
constructor
Inits a new restriction.
-
- (Object) validate(env, remote_addr)
Validates, if a request (with a remote_address) is allowed to access the requested path.
Constructor Details
- (Restriction) initialize(*args)
TODO:
Add other options, i.e. an array of IP groups :only => [:test1, :admins]
Inits a new restriction
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rack_ip_restrictor/restriction.rb', line 18 def initialize(*args) @options = args. raise Exception, "invalid argument" unless @options.has_key? :only and @options[:only].is_a? Symbol @paths = args @paths.each do |path| raise Exception, "invalid path argument" unless path.is_a? String or path.is_a? Regexp end end |
Instance Method Details
- (Object) validate(env, remote_addr)
Validates, if a request (with a remote_address) is allowed to access the requested path
32 33 34 35 36 37 38 39 40 |
# File 'lib/rack_ip_restrictor/restriction.rb', line 32 def validate(env, remote_addr) @paths.each do |path| if concerns_path?(env["PATH_INFO"]) and not concerns_ip?(remote_addr) return false end end true end |