Sha256: 2b547a4b1d52c61deebb9356d483b785b180e7eb7f9fd758bb5732f828470cea
Contents?: true
Size: 1.14 KB
Versions: 3
Compression:
Stored size: 1.14 KB
Contents
module Take2 class Configuration CONFIG_ATTRS = [:retries, :retriable, :retry_proc, :retry_condition_proc, :time_to_sleep].freeze attr_accessor(*CONFIG_ATTRS) def initialize(options = {}) # Defaults @retries = 3 @retriable = [ Net::HTTPServerError, Net::HTTPServerException, Net::HTTPRetriableError, Errno::ECONNRESET, IOError, ].freeze @retry_proc = proc {} @retry_condition_proc = proc { false } @time_to_sleep = 3 # Overwriting the defaults options.each do |k, v| raise ArgumentError, "#{k} is not a valid configuration" unless CONFIG_ATTRS.include?(k) raise ArgumentError, "#{k} must be positive integer" unless v.is_a?(Integer) && v.positive? raise ArgumentError, "#{k} must be positive number" unless (v.is_a?(Integer) || v.is_a?(Float)) && v.positive? instance_variable_set(:"@#{k}", v) end end def to_hash CONFIG_ATTRS.each_with_object({}) do |key, hash| hash[key] = public_send(key) end end def [](value) self.public_send(value) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
take2-0.0.2 | lib/take2/configuration.rb |
take2-0.0.1 | lib/take2/configuration.rb |
take2-0.0.0 | lib/take2/configuration.rb |