Class: Floodgate::Config
- Inherits:
-
Object
- Object
- Floodgate::Config
- Defined in:
- lib/floodgate/config.rb
Class Attribute Summary collapse
-
.api_token ⇒ Object
Returns the value of attribute api_token.
-
.app_id ⇒ Object
Returns the value of attribute app_id.
Instance Attribute Summary collapse
-
#allowed_ip_addresses ⇒ Object
Returns the value of attribute allowed_ip_addresses.
-
#filter_traffic ⇒ Object
Returns the value of attribute filter_traffic.
-
#redirect_url ⇒ Object
Returns the value of attribute redirect_url.
Class Method Summary collapse
Instance Method Summary collapse
- #client_allowed?(env) ⇒ Boolean
- #filter_traffic?(env) ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #potential_client_addresses(env) ⇒ Object
- #redirect? ⇒ Boolean
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Config
16 17 18 19 20 21 22 |
# File 'lib/floodgate/config.rb', line 16 def initialize status = Client.status @filter_traffic = status.filter_traffic @redirect_url = status.redirect_url @allowed_ip_addresses = status.allowed_ip_addresses end |
Class Attribute Details
.api_token ⇒ Object
Returns the value of attribute api_token.
4 5 6 |
# File 'lib/floodgate/config.rb', line 4 def api_token @api_token end |
.app_id ⇒ Object
Returns the value of attribute app_id.
4 5 6 |
# File 'lib/floodgate/config.rb', line 4 def app_id @app_id end |
Instance Attribute Details
#allowed_ip_addresses ⇒ Object
Returns the value of attribute allowed_ip_addresses.
11 12 13 |
# File 'lib/floodgate/config.rb', line 11 def allowed_ip_addresses @allowed_ip_addresses end |
#filter_traffic ⇒ Object
Returns the value of attribute filter_traffic.
11 12 13 |
# File 'lib/floodgate/config.rb', line 11 def filter_traffic @filter_traffic end |
#redirect_url ⇒ Object
Returns the value of attribute redirect_url.
11 12 13 |
# File 'lib/floodgate/config.rb', line 11 def redirect_url @redirect_url end |
Class Method Details
.reset ⇒ Object
6 7 8 |
# File 'lib/floodgate/config.rb', line 6 def reset @app_id = @api_token = nil end |
Instance Method Details
#client_allowed?(env) ⇒ Boolean
28 29 30 31 32 |
# File 'lib/floodgate/config.rb', line 28 def client_allowed?(env) !!potential_client_addresses(env).find do |ip_address| allowed_ip_addresses.include?(ip_address) end end |
#filter_traffic?(env) ⇒ Boolean
34 35 36 |
# File 'lib/floodgate/config.rb', line 34 def filter_traffic?(env) filter_traffic && !client_allowed?(env) end |
#potential_client_addresses(env) ⇒ Object
24 25 26 |
# File 'lib/floodgate/config.rb', line 24 def potential_client_addresses(env) %w(REMOTE_ADDR HTTP_X_FORWARDED_FOR).map { |name| env[name] } end |
#redirect? ⇒ Boolean
38 39 40 |
# File 'lib/floodgate/config.rb', line 38 def redirect? !redirect_url.nil? && !redirect_url.empty? end |
#reset ⇒ Object
42 43 44 45 |
# File 'lib/floodgate/config.rb', line 42 def reset @redirect_url = nil @filter_traffic = false end |