Class: Locked::Configuration

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

Overview

manages configuration variables

Constant Summary collapse

HOST =
if ENV['DOCKER_USE'].to_i == 1
  'app'
elsif ENV['LOCKED_RUBY_DEV_MODE'].to_s == 'on'
  'localhost'
else
  'locked.jp'
end
PORT =
ENV['LOCKED_RUBY_DEV_MODE'] == 'on' ? 3000 : 443
URL_PREFIX =
'api/v1/client'
FAILOVER_STRATEGY =
:deny
REQUEST_TIMEOUT =

in milliseconds

1000
FAILOVER_STRATEGIES =
i[allow deny 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



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/locked/configuration.rb', line 38

def initialize
  @formatter = Locked::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_key = ''
  self.basic_auth = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



83
84
85
# File 'lib/locked/configuration.rb', line 83

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

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



36
37
38
# File 'lib/locked/configuration.rb', line 36

def api_key
  @api_key
end

#basic_authObject

Returns the value of attribute basic_auth.



35
36
37
# File 'lib/locked/configuration.rb', line 35

def basic_auth
  @basic_auth
end

#blacklistedObject

Returns the value of attribute blacklisted.



36
37
38
# File 'lib/locked/configuration.rb', line 36

def blacklisted
  @blacklisted
end

#failover_strategyObject

Returns the value of attribute failover_strategy.



36
37
38
# File 'lib/locked/configuration.rb', line 36

def failover_strategy
  @failover_strategy
end

#hostObject

Returns the value of attribute host.



35
36
37
# File 'lib/locked/configuration.rb', line 35

def host
  @host
end

#portObject

Returns the value of attribute port.



35
36
37
# File 'lib/locked/configuration.rb', line 35

def port
  @port
end

#request_timeoutObject

Returns the value of attribute request_timeout.



35
36
37
# File 'lib/locked/configuration.rb', line 35

def request_timeout
  @request_timeout
end

#url_prefixObject

Returns the value of attribute url_prefix.



35
36
37
# File 'lib/locked/configuration.rb', line 35

def url_prefix
  @url_prefix
end

#whitelistedObject

Returns the value of attribute whitelisted.



36
37
38
# File 'lib/locked/configuration.rb', line 36

def whitelisted
  @whitelisted
end

Instance Method Details

#valid?Boolean



63
64
65
# File 'lib/locked/configuration.rb', line 63

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