class Rack::NonCache::Engine

Attributes

blacklist[RW]
whitelist[RW]

Public Class Methods

new(backend, options) { |self| ... } click to toggle source
# File lib/rack/noncache/engine.rb, line 8
def initialize(backend, options)
  @backend = backend
  @whitelist = options[:whitelist]
  @blacklist = options[:blacklist]
  yield self if block_given?
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/noncache/engine.rb, line 15
def call(env)
  # execute the request using our backend
  status, headers, response = @backend.call(env)

  uri = env['REQUEST_URI']
  filters.each { |filter| filter.apply(headers) } if target_path? uri
  [status, headers, response]
end

Private Instance Methods

filters() click to toggle source
# File lib/rack/noncache/engine.rb, line 26
def filters
  [Http10Filter, Http11Filter, ProxyFilter, SecurityFilter,
   DeprecatedFilter]
end
match(list, uri) click to toggle source
# File lib/rack/noncache/engine.rb, line 41
def match(list, uri)
  list.index do |path|
    (path.class.eql?(String) && path.eql?(uri)) ||
      (path.class.eql?(Regexp) && path.match(uri))
  end
end
target_path?(uri) click to toggle source
# File lib/rack/noncache/engine.rb, line 31
def target_path?(uri)
  if @whitelist
    return match(@whitelist, uri)
  elsif @blacklist
    return !match(@blacklist, uri)
  else
    false
  end
end