Class: Castle::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/castle/configuration.rb

Overview

manages configuration variables

Constant Summary collapse

HOST =
'api.castle.io'
PORT =
443
URL_PREFIX =
'v1'
FAILOVER_STRATEGY =
:allow
REQUEST_TIMEOUT =

in milliseconds

500
FAILOVER_STRATEGIES =
%i[allow deny challenge throw].freeze
WHITELISTED =
[
  'User-Agent',
  'Accept-Language',
  'Accept-Encoding',
  'Accept-Charset',
  'Accept',
  'Accept-Datetime',
  'X-Forwarded-For',
  'Forwarded',
  'X-Forwarded',
  'X-Real-IP',
  'REMOTE_ADDR',
  'X-Forwarded-For',
  'CF_CONNECTING_IP'
].freeze
BLACKLISTED =
['HTTP_COOKIE'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/castle/configuration.rb', line 32

def initialize
  @formatter = Castle::HeaderFormatter.new
  @request_timeout = REQUEST_TIMEOUT
  self.failover_strategy = FAILOVER_STRATEGY
  self.host = HOST
  self.port = PORT
  self.url_prefix = URL_PREFIX
  self.whitelisted = WHITELISTED
  self.blacklisted = BLACKLISTED
  self.api_secret = ''
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(setting, *_args) ⇒ Object (private)



71
72
73
# File 'lib/castle/configuration.rb', line 71

def method_missing(setting, *_args)
  raise Castle::ConfigurationError, "there is no such a config #{setting}"
end

Instance Attribute Details

#api_secretObject

Returns the value of attribute api_secret.



30
31
32
# File 'lib/castle/configuration.rb', line 30

def api_secret
  @api_secret
end

#blacklistedObject

Returns the value of attribute blacklisted.



30
31
32
# File 'lib/castle/configuration.rb', line 30

def blacklisted
  @blacklisted
end

#failover_strategyObject

Returns the value of attribute failover_strategy.



30
31
32
# File 'lib/castle/configuration.rb', line 30

def failover_strategy
  @failover_strategy
end

#hostObject

Returns the value of attribute host.



29
30
31
# File 'lib/castle/configuration.rb', line 29

def host
  @host
end

#portObject

Returns the value of attribute port.



29
30
31
# File 'lib/castle/configuration.rb', line 29

def port
  @port
end

#request_timeoutObject

Returns the value of attribute request_timeout.



29
30
31
# File 'lib/castle/configuration.rb', line 29

def request_timeout
  @request_timeout
end

#url_prefixObject

Returns the value of attribute url_prefix.



29
30
31
# File 'lib/castle/configuration.rb', line 29

def url_prefix
  @url_prefix
end

#whitelistedObject

Returns the value of attribute whitelisted.



30
31
32
# File 'lib/castle/configuration.rb', line 30

def whitelisted
  @whitelisted
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/castle/configuration.rb', line 56

def valid?
  !api_secret.to_s.empty? && !host.to_s.empty? && !port.to_s.empty?
end