File tree Expand file tree Collapse file tree 2 files changed +34
-21
lines changed
Expand file tree Collapse file tree 2 files changed +34
-21
lines changed Original file line number Diff line number Diff line change @@ -94,27 +94,7 @@ def timeout(options)
9494 klass , options = case options
9595 when Numeric then [ HTTP ::Timeout ::Global , { :global_timeout => options } ]
9696 when Hash
97- options = options . dup
98- %i[ read write connect ] . each do |k |
99- next unless options . key? k
100-
101- if options . key? ( "#{ k } _timeout" . to_sym )
102- raise ArgumentError , "can't pass both #{ k } and #{ "#{ k } _timeout" . to_sym } "
103- end
104-
105- options [ "#{ k } _timeout" . to_sym ] = options . delete k
106- end
107-
108- options . each do |key , value |
109- unless HTTP ::Timeout ::PerOperation ::SETTINGS . member? ( key ) && value . is_a? ( Numeric )
110- raise ArgumentError , "invalid option #{ key . inspect } , must be numeric " \
111- "`.timeout(connect: x, write: y, read: z)`."
112- end
113- end
114-
115- raise ArgumentError , "at least one option" if options . empty?
116-
117- [ HTTP ::Timeout ::PerOperation , options . dup ]
97+ [ HTTP ::Timeout ::PerOperation , HTTP ::Timeout ::PerOperation . parse_options ( options ) ]
11898 when :null then [ HTTP ::Timeout ::Null , { } ]
11999 else raise ArgumentError , "Use `.timeout(:null)`, " \
120100 "`.timeout(global_timeout_in_seconds)` or " \
Original file line number Diff line number Diff line change @@ -12,6 +12,39 @@ class PerOperation < Null
1212 READ_TIMEOUT = 0.25
1313
1414 SETTINGS = Set . new ( %i[ read_timeout write_timeout connect_timeout ] )
15+
16+ class << self
17+ def parse_options ( options )
18+ options = options . dup . then { |opts | expand_names ( opts ) }
19+ options . each do |key , value |
20+ unless SETTINGS . member? ( key ) && value . is_a? ( Numeric )
21+ raise ArgumentError , "invalid option #{ key . inspect } , must be numeric " \
22+ "`.timeout(connect: x, write: y, read: z)`."
23+ end
24+ end
25+
26+ raise ArgumentError , "at least one option" if options . empty?
27+
28+ options
29+ end
30+
31+ private
32+
33+ def expand_names ( options )
34+ %i[ read write connect ] . each do |k |
35+ next unless options . key? k
36+
37+ if options . key? ( "#{ k } _timeout" . to_sym )
38+ raise ArgumentError , "can't pass both #{ k } and #{ "#{ k } _timeout" . to_sym } "
39+ end
40+
41+ options [ "#{ k } _timeout" . to_sym ] = options . delete k
42+ end
43+
44+ options
45+ end
46+ end
47+
1548 def initialize ( *args )
1649 super
1750
You can’t perform that action at this time.
0 commit comments