Class: Castle::Configuration

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

Overview

manages configuration variables

Constant Summary collapse

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'
].freeze
BLACKLISTED =
['HTTP_COOKIE'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/castle/configuration.rb', line 27

def initialize
  @formatter = Castle::HeaderFormatter.new
  @request_timeout = REQUEST_TIMEOUT
  self.failover_strategy = :allow
  self.host = 'api.castle.io'
  self.port = 443
  self.url_prefix = 'v1'
  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(m, *_args) ⇒ Object (private)



67
68
69
# File 'lib/castle/configuration.rb', line 67

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

Instance Attribute Details

#api_secretObject

Returns the value of attribute api_secret.



25
26
27
# File 'lib/castle/configuration.rb', line 25

def api_secret
  @api_secret
end

#blacklistedObject

Returns the value of attribute blacklisted.



25
26
27
# File 'lib/castle/configuration.rb', line 25

def blacklisted
  @blacklisted
end

#failover_strategyObject

Returns the value of attribute failover_strategy.



25
26
27
# File 'lib/castle/configuration.rb', line 25

def failover_strategy
  @failover_strategy
end

#hostObject

Returns the value of attribute host.



24
25
26
# File 'lib/castle/configuration.rb', line 24

def host
  @host
end

#portObject

Returns the value of attribute port.



24
25
26
# File 'lib/castle/configuration.rb', line 24

def port
  @port
end

#request_timeoutObject

Returns the value of attribute request_timeout.



24
25
26
# File 'lib/castle/configuration.rb', line 24

def request_timeout
  @request_timeout
end

#url_prefixObject

Returns the value of attribute url_prefix.



24
25
26
# File 'lib/castle/configuration.rb', line 24

def url_prefix
  @url_prefix
end

#whitelistedObject

Returns the value of attribute whitelisted.



25
26
27
# File 'lib/castle/configuration.rb', line 25

def whitelisted
  @whitelisted
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/castle/configuration.rb', line 51

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