class Floodgate::Config

Attributes

api_token[RW]
app_id[RW]
allowed_ip_addresses[RW]
filter_traffic[RW]
redirect_url[RW]

Public Class Methods

new() click to toggle source
# File lib/floodgate/config.rb, line 20
def initialize
  status = Client.status

  @filter_traffic = status.filter_traffic
  @redirect_url = status.redirect_url
  @allowed_ip_addresses = status.allowed_ip_addresses
end
reset() click to toggle source
# File lib/floodgate/config.rb, line 6
def reset
  @app_id = @api_token = nil
end
test?() click to toggle source
# File lib/floodgate/config.rb, line 10
def test?
  ENV.has_key?('FLOODGATE_TEST_MODE')
end

Public Instance Methods

client_allowed?(env) click to toggle source
# File lib/floodgate/config.rb, line 32
def client_allowed?(env)
  !!potential_client_addresses(env).find do |ip_address|
    allowed_ip_addresses.include?(ip_address)
  end
end
filter_traffic?(env) click to toggle source
# File lib/floodgate/config.rb, line 38
def filter_traffic?(env)
  filter_traffic && !client_allowed?(env)
end
potential_client_addresses(env) click to toggle source
# File lib/floodgate/config.rb, line 28
def potential_client_addresses(env)
  %w(REMOTE_ADDR HTTP_X_FORWARDED_FOR).map { |name| env[name] }
end
redirect?() click to toggle source
# File lib/floodgate/config.rb, line 42
def redirect?
  !redirect_url.nil? && !redirect_url.empty?
end
reset() click to toggle source
# File lib/floodgate/config.rb, line 46
def reset
  @redirect_url = nil
  @filter_traffic = false
end