class StrongRoutes::Allow
Public Class Methods
new(app, options = {})
click to toggle source
# File lib/strong_routes/allow.rb, line 3 def initialize(app, options = {}) @app = app @options = options end
Public Instance Methods
_call(env)
click to toggle source
# File lib/strong_routes/allow.rb, line 8 def _call(env) return @app.call(env) unless enabled? request = ::Rack::Request.new(env) if allowed?(request) @app.call(env) else [ 404, { "Content-Type" => "text/html", "Content-Length" => config.message.length.to_s }, [ config.message ] ] end end
call(env)
click to toggle source
HACK: This makes this middleware threadsafe, but is not a very good pattern. We should rewrite this to use a separate class with instance-level stuff.
# File lib/strong_routes/allow.rb, line 22 def call(env) dup._call(env) end
Private Instance Methods
allowed?(request)
click to toggle source
# File lib/strong_routes/allow.rb, line 38 def allowed?(request) route_matchers.any? { |route_matcher| route_matcher =~ request.path_info } end
allowed_routes()
click to toggle source
# File lib/strong_routes/allow.rb, line 28 def allowed_routes @allowed_routes ||= begin routes = [ config.allowed_routes ] routes.flatten! routes.compact! routes.uniq! routes end end
config()
click to toggle source
# File lib/strong_routes/allow.rb, line 42 def config @config ||= StrongRoutes.config.merge(@options) end
enabled?()
click to toggle source
# File lib/strong_routes/allow.rb, line 46 def enabled? config.enabled? end
route_matchers()
click to toggle source
# File lib/strong_routes/allow.rb, line 50 def route_matchers @route_matchers ||= allowed_routes.map { |allowed_route| ::StrongRoutes::RouteMatcher.new(allowed_route) } end