class Take2::Configuration
Constants
- CONFIG_ATTRS
Public Class Methods
new(options = {})
click to toggle source
# File lib/take2/configuration.rb, line 15 def initialize(options = {}) # Defaults @retries = 3 @retriable = [] @retry_proc = proc {} @retry_condition_proc = proc { false } @backoff_intervals = Backoff.new(:constant, 3).intervals merge_options!(options) end
Public Instance Methods
[](value)
click to toggle source
# File lib/take2/configuration.rb, line 32 def [](value) public_send(value) end
merge_options!(options = {})
click to toggle source
# File lib/take2/configuration.rb, line 36 def merge_options!(options = {}) validate!(options).each do |key, value| public_send("#{key}=", value) end self end
to_hash()
click to toggle source
# File lib/take2/configuration.rb, line 26 def to_hash CONFIG_ATTRS.each_with_object({}) do |key, hash| hash[key] = public_send(key) end end
validate!(options)
click to toggle source
# File lib/take2/configuration.rb, line 43 def validate!(options) options.each do |k, v| raise ArgumentError, "#{k} is not a valid configuration" unless CONFIG_ATTRS.include?(k) case k when :retries raise ArgumentError, "#{k} must be positive integer" unless v.is_a?(Integer) && v.positive? when :retriable raise ArgumentError, "#{k} must be array of retriable errors" unless v.is_a?(Array) when :backoff_intervals raise ArgumentError, "#{k} must be array of retriable errors" unless v.is_a?(Array) raise ArgumentError, "#{k} size must be greater or equal to number of retries" unless v.size >= retries when :retry_proc, :retry_condition_proc raise ArgumentError, "#{k} must be Proc" unless v.is_a?(Proc) end end end