Class: Cors::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cors/config.rb,
lib/cors/config/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.2.6"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, user_config = 'config/cors.yml') ⇒ Config

Returns a new instance of Config.



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

def initialize(app, user_config = 'config/cors.yml')
  @app = app
  @user_config = user_config
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



8
9
10
# File 'lib/cors/config.rb', line 8

def app
  @app
end

#user_configObject

Returns the value of attribute user_config.



8
9
10
# File 'lib/cors/config.rb', line 8

def user_config
  @user_config
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/cors/config.rb', line 15

def call(env)
  config = configure_cors
  return @app.call(env) if config.empty?
  cors = generate_cors_rules_from_config(config)
  return @app.call(env) if cors.nil? 
  cors.call(env)
rescue => error
  raise Error.new("Unexpected error #{error.message}")
end