Compare commits

...

2 Commits

Author SHA1 Message Date
HoneyryderChuck
4292644870 Merge branch 'issue-247' into 'master'
fix Session class assertions not prepared for class overrides

Closes #247

See merge request os85/httpx!274
2023-09-19 16:07:08 +00:00
HoneyryderChuck
2e11ee5b32 fix Session class assertions not prepared for class overrides
Some plugins override the Session class, however there may be instances
of the original Session around, therefore the assertions need to somehow
point to the original Session class to stil be able to work.

Closes #247
2023-09-19 09:33:01 +01:00
2 changed files with 6 additions and 3 deletions

View File

@ -48,7 +48,7 @@ module HTTPX
end end
def plugin(pl, options = nil, &blk) def plugin(pl, options = nil, &blk)
klass = is_a?(Session) ? self.class : Session klass = is_a?(S) ? self.class : Session
klass = Class.new(klass) klass = Class.new(klass)
klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options)) klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options))
klass.plugin(pl, options, &blk).new klass.plugin(pl, options, &blk).new
@ -58,7 +58,7 @@ module HTTPX
# :nocov: # :nocov:
def plugins(pls) def plugins(pls)
warn ":#{__method__} is deprecated, use :plugin instead" warn ":#{__method__} is deprecated, use :plugin instead"
klass = is_a?(Session) ? self.class : Session klass = is_a?(S) ? self.class : Session
klass = Class.new(klass) klass = Class.new(klass)
klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options)) klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options))
klass.plugins(pls).new klass.plugins(pls).new
@ -82,7 +82,7 @@ module HTTPX
end end
def branch(options, &blk) def branch(options, &blk)
return self.class.new(options, &blk) if is_a?(Session) return self.class.new(options, &blk) if is_a?(S)
Session.new(options, &blk) Session.new(options, &blk)
end end

View File

@ -351,4 +351,7 @@ module HTTPX
# :nocov: # :nocov:
end end
end end
# session may be overridden by certain adapters.
S = Session
end end