class Rack::Cors::Resources
Attributes
Public Class Methods
Source
# File lib/rack/cors.rb, line 286 def initialize @origins = [] @resources = [] @public_resources = false end
Public Instance Methods
Source
# File lib/rack/cors.rb, line 314 def allow_origin?(source,env = {}) return true if public_resources? return !! @origins.detect do |origin| if origin.is_a?(Proc) origin.call(source,env) else origin === source end end end
Source
# File lib/rack/cors.rb, line 326 def match_resource(path, env) @resources.detect { |r| r.match?(path, env) } end
Source
# File lib/rack/cors.rb, line 292 def origins(*args, &blk) @origins = args.flatten.reject{ |s| s == '' }.map do |n| case n when Proc, Regexp, /^https?:\/\//, 'file://' then n when '*' then @public_resources = true; n else Regexp.compile("^[a-z][a-z0-9.+-]*:\\\/\\\/#{Regexp.quote(n)}$") end end.flatten @origins.push(blk) if blk end
Source
# File lib/rack/cors.rb, line 310 def public_resources? @public_resources end
Source
# File lib/rack/cors.rb, line 306 def resource(path, opts={}) @resources << Resource.new(public_resources?, path, opts) end
Source
# File lib/rack/cors.rb, line 330 def resource_for_path(path) @resources.detect { |r| r.matches_path?(path) } end