class Locked::Configuration

manages configuration variables

Constants

BLACKLISTED
FAILOVER_STRATEGIES
FAILOVER_STRATEGY
HOST
PORT
REQUEST_TIMEOUT
URL_PREFIX
WHITELISTED

Attributes

api_key[R]
basic_auth[RW]
blacklisted[R]
failover_strategy[R]
host[RW]
port[RW]
request_timeout[RW]
url_prefix[RW]
whitelisted[R]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

api_key=(value) click to toggle source
# File lib/locked/configuration.rb, line 51
def api_key=(value)
  @api_key = ENV.fetch('X_LOCKED_API_KEY', value).to_s
end
basic_auth=(value) click to toggle source
# File lib/locked/configuration.rb, line 72
def basic_auth=(value)
  return @basic_auth = {} unless value.has_key?(:username) && value.has_key?(:password)
  @basic_auth = value
end
blacklisted=(value) click to toggle source
# File lib/locked/configuration.rb, line 59
def blacklisted=(value)
  @blacklisted = (value ? value.map { |header| @formatter.call(header) } : []).freeze
end
failover_strategy=(value) click to toggle source
# File lib/locked/configuration.rb, line 67
def failover_strategy=(value)
  @failover_strategy = FAILOVER_STRATEGIES.detect { |strategy| strategy == value.to_sym }
  raise Locked::ConfigurationError, 'unrecognized failover strategy' if @failover_strategy.nil?
end
valid?() click to toggle source
# File lib/locked/configuration.rb, line 63
def valid?
  !api_key.to_s.empty? && !host.to_s.empty? && !port.to_s.empty?
end
whitelisted=(value) click to toggle source
# File lib/locked/configuration.rb, line 55
def whitelisted=(value)
  @whitelisted = (value ? value.map { |header| @formatter.call(header) } : []).freeze
end

Private Instance Methods

method_missing(setting, *_args) click to toggle source
# File lib/locked/configuration.rb, line 83
def method_missing(setting, *_args)
  raise Locked::ConfigurationError, "there is no such a config #{setting}"
end
respond_to_missing?(method_name, _include_private) click to toggle source
# File lib/locked/configuration.rb, line 79
def respond_to_missing?(method_name, _include_private)
  /^(\w+)=$/ =~ method_name
end