module Phobos
Please use this with at least the same consideration as you would when using OpenStruct. Right now we only use this to parse our internal configuration files. It is not meant to be used on incoming data.
Constants
- VERSION
Attributes
config[R]
logger[R]
silence_log[RW]
Public Class Methods
add_listeners(configuration)
click to toggle source
# File lib/phobos.rb, line 68 def add_listeners(configuration) listeners_config = fetch_configuration(configuration) @config.listeners += listeners_config.listeners end
configure(configuration)
click to toggle source
# File lib/phobos.rb, line 56 def configure(configuration) @config = fetch_configuration(configuration) @config.class.send(:define_method, :producer_hash) do Phobos.config.producer&.to_hash&.except(:kafka) end @config.class.send(:define_method, :consumer_hash) do Phobos.config.consumer&.to_hash&.except(:kafka) end @config.listeners ||= [] configure_logger end
create_exponential_backoff(backoff_config = nil)
click to toggle source
# File lib/phobos.rb, line 83 def create_exponential_backoff(backoff_config = nil) backoff_config ||= Phobos.config.backoff.to_hash min = backoff_config[:min_ms] / 1000.0 max = backoff_config[:max_ms] / 1000.0 ExponentialBackoff.new(min, max).tap { |backoff| backoff.randomize_factor = rand } end
create_kafka_client(config_key = nil)
click to toggle source
# File lib/phobos.rb, line 73 def create_kafka_client(config_key = nil) kafka_config = config.kafka.to_hash.merge(logger: @ruby_kafka_logger) if config_key kafka_config = kafka_config.merge(**config.send(config_key)&.kafka&.to_hash || {}) end Kafka.new(**kafka_config) end
deprecate(message)
click to toggle source
# File lib/phobos.rb, line 90 def deprecate(message) location = caller.find { |line| line !~ %r{/phobos/} } warn "DEPRECATION WARNING: #{message}: #{location}" end