Class: Racecar::Config
- Inherits:
-
KingKonf::Config
- Object
- KingKonf::Config
- Racecar::Config
- Defined in:
- lib/racecar/config.rb
Instance Attribute Summary collapse
-
#error_handler ⇒ Object
readonly
The error handler must be set directly on the object.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#subscriptions ⇒ Object
Returns the value of attribute subscriptions.
Instance Method Summary collapse
-
#initialize(env: ENV) ⇒ Config
constructor
A new instance of Config.
- #inspect ⇒ Object
- #load_consumer_class(consumer_class) ⇒ Object
- #on_error(&handler) ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(env: ENV) ⇒ Config
Returns a new instance of Config.
138 139 140 141 142 143 |
# File 'lib/racecar/config.rb', line 138 def initialize(env: ENV) super(env: env) @error_handler = proc {} @subscriptions = [] @logger = Logger.new(STDOUT) end |
Instance Attribute Details
#error_handler ⇒ Object (readonly)
The error handler must be set directly on the object.
134 135 136 |
# File 'lib/racecar/config.rb', line 134 def error_handler @error_handler end |
#logger ⇒ Object
Returns the value of attribute logger.
136 137 138 |
# File 'lib/racecar/config.rb', line 136 def logger @logger end |
#subscriptions ⇒ Object
Returns the value of attribute subscriptions.
136 137 138 |
# File 'lib/racecar/config.rb', line 136 def subscriptions @subscriptions end |
Instance Method Details
#inspect ⇒ Object
145 146 147 148 149 150 |
# File 'lib/racecar/config.rb', line 145 def inspect self.class.variables .map(&:name) .map {|key| [key, get(key).inspect].join(" = ") } .join("\n") end |
#load_consumer_class(consumer_class) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/racecar/config.rb', line 170 def load_consumer_class(consumer_class) self.group_id = consumer_class.group_id || self.group_id self.group_id ||= [ # Configurable and optional prefix: group_id_prefix, # MyFunnyConsumer => my-funny-consumer consumer_class.name.gsub(/[a-z][A-Z]/) {|str| str[0] << "-" << str[1] }.downcase, ].compact.join("") self.subscriptions = consumer_class.subscriptions self.max_wait_time = consumer_class.max_wait_time || self.max_wait_time self.offset_retention_time = consumer_class.offset_retention_time || self.offset_retention_time self.pidfile ||= "#{group_id}.pid" end |
#on_error(&handler) ⇒ Object
187 188 189 |
# File 'lib/racecar/config.rb', line 187 def on_error(&handler) @error_handler = handler end |
#validate! ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/racecar/config.rb', line 152 def validate! if brokers.empty? raise ConfigError, "`brokers` must not be empty" end if socket_timeout <= max_wait_time raise ConfigError, "`socket_timeout` must be longer than `max_wait_time`" end if connect_timeout <= max_wait_time raise ConfigError, "`connect_timeout` must be longer than `max_wait_time`" end if max_pause_timeout && !pause_with_exponential_backoff? raise ConfigError, "`max_pause_timeout` only makes sense when `pause_with_exponential_backoff` is enabled" end end |