Class: Yandex360::Configuration
- Inherits:
-
Object
- Object
- Yandex360::Configuration
- Defined in:
- lib/yandex360/configuration.rb
Overview
Defaults for every client, set once at boot.
Yandex360.configure do |config|
config.token = ENV.fetch("YA360_TOKEN")
config.logger = Rails.logger
end
A client reads these when it is built and copies what it needs, so nothing here is consulted while a request is in flight. Anything passed to Yandex360::Client.new wins over what is set here.
Constant Summary collapse
- DEFAULT_OPEN_TIMEOUT =
Seconds to wait for the connection to be established.
5- DEFAULT_TIMEOUT =
Seconds to wait for the response to complete.
30- DEFAULT_MAX_RETRIES =
Retries attempted on top of the initial request.
2- DEFAULT_RETRY_INTERVAL =
Seconds before the first retry. Doubles on each subsequent attempt.
0.5- SETTINGS =
%i[token adapter logger open_timeout timeout max_retries retry_interval].freeze
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#retry_interval ⇒ Object
Returns the value of attribute retry_interval.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#inspect ⇒ Object
Never let a token reach a log, an error tracker or a console transcript.
-
#merge(overrides) ⇒ Object
A copy with the overrides applied.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
27 28 29 30 31 32 33 34 35 |
# File 'lib/yandex360/configuration.rb', line 27 def initialize @token = nil @adapter = nil @logger = nil @open_timeout = DEFAULT_OPEN_TIMEOUT @timeout = DEFAULT_TIMEOUT @max_retries = DEFAULT_MAX_RETRIES @retry_interval = DEFAULT_RETRY_INTERVAL end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
24 25 26 |
# File 'lib/yandex360/configuration.rb', line 24 def adapter @adapter end |
#logger ⇒ Object
Returns the value of attribute logger.
24 25 26 |
# File 'lib/yandex360/configuration.rb', line 24 def logger @logger end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
24 25 26 |
# File 'lib/yandex360/configuration.rb', line 24 def max_retries @max_retries end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
24 25 26 |
# File 'lib/yandex360/configuration.rb', line 24 def open_timeout @open_timeout end |
#retry_interval ⇒ Object
Returns the value of attribute retry_interval.
24 25 26 |
# File 'lib/yandex360/configuration.rb', line 24 def retry_interval @retry_interval end |
#timeout ⇒ Object
Returns the value of attribute timeout.
24 25 26 |
# File 'lib/yandex360/configuration.rb', line 24 def timeout @timeout end |
#token ⇒ Object
Returns the value of attribute token.
24 25 26 |
# File 'lib/yandex360/configuration.rb', line 24 def token @token end |
Instance Method Details
#inspect ⇒ Object
Never let a token reach a log, an error tracker or a console transcript.
52 53 54 55 56 |
# File 'lib/yandex360/configuration.rb', line 52 def inspect "#<#{self.class.name} token=#{token.nil? ? 'nil' : '***'} " \ "timeout=#{timeout} open_timeout=#{open_timeout} " \ "max_retries=#{max_retries} retry_interval=#{retry_interval}>" end |
#merge(overrides) ⇒ Object
A copy with the overrides applied. Anything nil is left alone, so a client only has to pass what it wants to change, and the resolution happens here rather than as a row of fallbacks in the constructor.
42 43 44 45 46 47 48 49 |
# File 'lib/yandex360/configuration.rb', line 42 def merge(overrides) copy = dup SETTINGS.each do |setting| value = overrides[setting] copy.public_send("#{setting}=", value) unless value.nil? end copy end |