Class: Liberty::CORS

Inherits:
Object
  • Object
show all
Defined in:
lib/liberty/cors.rb,
lib/liberty/cors/middleware.rb

Defined Under Namespace

Classes: Middleware

Constant Summary collapse

ACCESS_CONTROL_HEADER =
"Access-Control-Allow-Origin"

Class Method Summary collapse

Class Method Details

.access_control_headerObject



18
19
20
# File 'lib/liberty/cors.rb', line 18

def access_control_header
  headers.slice(ACCESS_CONTROL_HEADER)
end

.config {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Liberty::CORS)

    the object that the method was called on



10
11
12
# File 'lib/liberty/cors.rb', line 10

def config
  yield(self)
end

.configured?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/liberty/cors.rb', line 14

def configured?
  !@headers.nil? && !@headers.empty?
end

.headersObject



22
23
24
# File 'lib/liberty/cors.rb', line 22

def headers
  @headers ||= {}
end

.headers=(headers) ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
30
# File 'lib/liberty/cors.rb', line 26

def headers=(headers)
  raise ArgumentError.new("Expected headers to be a Hash, received a #{headers.class} instead") unless headers.is_a?(Hash)

  @headers = headers
end