Class: ShopifyAPIRetry::Config
- Inherits:
-
Object
- Object
- ShopifyAPIRetry::Config
- Defined in:
- lib/shopify_api_retry.rb
Overview
:nodoc:
Instance Attribute Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #merge(userconfig) ⇒ Object
- #on(errors, options = nil) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
16 17 18 |
# File 'lib/shopify_api_retry.rb', line 16 def initialize @settings = {} end |
Instance Attribute Details
#default_tries ⇒ Object
24 25 26 |
# File 'lib/shopify_api_retry.rb', line 24 def default_tries @default_tries ||= 2 end |
#default_wait ⇒ Object
20 21 22 |
# File 'lib/shopify_api_retry.rb', line 20 def default_wait @default_wait ||= nil end |
Instance Method Details
#clear ⇒ Object
38 39 40 41 42 |
# File 'lib/shopify_api_retry.rb', line 38 def clear @settings.clear @default_wait = nil @default_tries = nil end |
#merge(userconfig) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/shopify_api_retry.rb', line 44 def merge(userconfig) config = to_h return config unless userconfig if userconfig.is_a?(Integer) warn "#{self.class}: using an Integer for the retry time is deprecated and will be removed, use :wait => #{userconfig} instead" userconfig = { :wait => userconfig } elsif !userconfig.is_a?(Hash) raise ArgumentError, "config must be a Hash" end userconfig.each do |k, v| if v.is_a?(Hash) config[k.to_s] = v.dup else config["graphql"][k] = config[REST::HTTP_RETRY_STATUS][k] = v end end config.values.each do |cfg| raise ArgumentError, "seconds to wait must be >= 0" if cfg[:wait] && cfg[:wait] < 0 end config end |
#on(errors, options = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/shopify_api_retry.rb', line 28 def on(errors, = nil) = ( || {}).dup [:wait] ||= default_wait [:tries] ||= default_tries Array(errors).each do |status_or_class| @settings[status_or_class] = end end |
#to_h ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/shopify_api_retry.rb', line 70 def to_h settings = { "graphql" => { :tries => default_tries, :wait => default_wait }, REST::HTTP_RETRY_STATUS => { :tries => default_tries, :wait => default_wait } } @settings.each_with_object(settings) { |(k, v), o| o[k.to_s] = v.dup } end |