In Files

Parent

Class/Module Index [+]

Quicksearch

Rack::Cors::Resources

Public Class Methods

new() click to toggle source
# File lib/rack/cors.rb, line 101
def initialize
  @origins = []
  @resources = []
  @public_resources = false
end

Public Instance Methods

allow_origin?(source,env = {}) click to toggle source
# File lib/rack/cors.rb, line 127
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
find_resource(path) click to toggle source
# File lib/rack/cors.rb, line 138
def find_resource(path)
  @resources.detect{|r| r.match?(path)}
end
origins(*args,&blk) click to toggle source
# File lib/rack/cors.rb, line 107
def origins(*args,&blk)
  @origins = args.flatten.collect do |n|
    case n
    when Regexp, /^https?:\/\// then n
    when 'file://'              then n
    when '*'                    then @public_resources = true; n
    else                        ["http://#{n}", "https://#{n}"]
    end
  end.flatten
  @origins.push(blk) if blk
end
public_resources?() click to toggle source
# File lib/rack/cors.rb, line 123
def public_resources?
  @public_resources
end
resource(path, opts={}) click to toggle source
# File lib/rack/cors.rb, line 119
def resource(path, opts={})
  @resources << Resource.new(public_resources?, path, opts)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.