Class: Floodgate::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/floodgate/control.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, app_id, api_token) ⇒ Control

Returns a new instance of Control.



5
6
7
8
9
10
11
# File 'lib/floodgate/control.rb', line 5

def initialize(app, app_id, api_token)
  Config.app_id = app_id
  Config.api_token = api_token

  @app = app
  @config = Config.new
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



3
4
5
# File 'lib/floodgate/control.rb', line 3

def app
  @app
end

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/floodgate/control.rb', line 3

def config
  @config
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/floodgate/control.rb', line 13

def call(env)
  return app.call(env) unless filter_traffic?(env)

  if redirect?
    [307, { 'Location' => redirect_url }, []]
  else
    [503, {}, ['Application Unavailable']]
  end
end

#filter_traffic?(env) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/floodgate/control.rb', line 23

def filter_traffic?(env)
  config.filter_traffic?(env)
end

#redirect?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/floodgate/control.rb', line 27

def redirect?
  config.redirect?
end

#redirect_urlObject



31
32
33
# File 'lib/floodgate/control.rb', line 31

def redirect_url
  config.redirect_url
end