class Rack::Restrictor

Constants

PAGE_CODE

Public Class Methods

new(app, plage) click to toggle source
# File lib/rack_restrictor.rb, line 17
    def initialize(app, plage)
            @app   = app
@plage = IPAddr.new( plage.to_s )    
    end

Public Instance Methods

call(env) click to toggle source
# File lib/rack_restrictor.rb, line 22
  def call(env)
          if authorized?( env['REMOTE_ADDR'].to_s )
                  status, headers, body = @app.call(env)
          else
                  status, headers, body = 
[401, {"Content-Type" => "text/html"}, PAGE_CODE]
          end

          [status, headers, body]
  end

Private Instance Methods

authorized?( ip ) click to toggle source
# File lib/rack_restrictor.rb, line 35
      def authorized?( ip )
              @plage.include?(IPAddr.new( ip ))
end