Class: Hoss::CentralConfig Private
- Inherits:
-
Object
- Object
- Hoss::CentralConfig
- Includes:
- Logging
- Defined in:
- lib/hoss/central_config.rb,
lib/hoss/central_config/cache_control.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: CacheControl, ClientError, ResponseError, ServerError
Constant Summary
Constants included from Logging
Logging::LEVELS, Logging::PREFIX
Instance Attribute Summary collapse
- #config ⇒ Object readonly private
-
#promise ⇒ Object
readonly
private
for specs.
-
#scheduled_task ⇒ Object
readonly
private
for specs.
Instance Method Summary collapse
- #assign(update) ⇒ Object private
- #fetch_and_apply_config ⇒ Object private
- #fetch_config ⇒ Object private
- #handle_forking! ⇒ Object private
-
#initialize(config) ⇒ CentralConfig
constructor
private
A new instance of CentralConfig.
- #start ⇒ Object private
- #stop ⇒ Object private
Methods included from Logging
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(config) ⇒ CentralConfig
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of CentralConfig.
38 39 40 41 42 43 44 |
# File 'lib/hoss/central_config.rb', line 38 def initialize(config) @config = config @modified_options = {} @authorization = "Bearer #{@config.api_key}" @http = Transport::Connection::Http.new(config) @etag = 1 end |
Instance Attribute Details
#config ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 |
# File 'lib/hoss/central_config.rb', line 46 def config @config end |
#promise ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
for specs
47 48 49 |
# File 'lib/hoss/central_config.rb', line 47 def promise @promise end |
#scheduled_task ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
for specs
47 48 49 |
# File 'lib/hoss/central_config.rb', line 47 def scheduled_task @scheduled_task end |
Instance Method Details
#assign(update) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/hoss/central_config.rb', line 87 def assign(update) # For each updated option, store the original value, # unless already stored update.each_key do |key| @modified_options[key] ||= config.get(key.to_sym)&.value end # If the new update doesn't set a previously modified option, # revert it to the original @modified_options.each_key do |key| next if update.key?(key) update[key] = @modified_options.delete(key) end @config.(update) end |
#fetch_and_apply_config ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 66 67 68 69 |
# File 'lib/hoss/central_config.rb', line 63 def fetch_and_apply_config @promise = Concurrent::Promise .execute(&method(:fetch_config)) .on_success(&method(:handle_success)) .rescue(&method(:handle_error)) end |
#fetch_config ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/hoss/central_config.rb', line 71 def fetch_config resp = perform_request case resp.status when 200..299 resp when 300..399 resp when 400..499 resp # raise ClientError, resp when 500..599 resp # raise ServerError, resp end end |
#handle_forking! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
103 104 105 106 |
# File 'lib/hoss/central_config.rb', line 103 def handle_forking! stop start end |
#start ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 52 53 54 55 |
# File 'lib/hoss/central_config.rb', line 49 def start return unless config.central_config? debug 'Starting CentralConfig' fetch_and_apply_config end |
#stop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 60 61 |
# File 'lib/hoss/central_config.rb', line 57 def stop debug 'Stopping CentralConfig' @scheduled_task&.cancel end |