class VCR::HTTPInteraction::HookAware
Decorates an {HTTPInteraction} with additional methods useful for a `before_record` or `before_playback` hook.
Public Class Methods
new(http_interaction)
click to toggle source
Calls superclass method
# File lib/vcr/structs.rb, line 508 def initialize(http_interaction) @ignored = false super end
Public Instance Methods
filter!(text, replacement_text)
click to toggle source
Replaces a string in any part of the HTTP interaction (headers, request body, response body, etc) with the given replacement text.
@param [#to_s] text the text to replace @param [#to_s] replacement_text the text to put in its place
# File lib/vcr/structs.rb, line 532 def filter!(text, replacement_text) text, replacement_text = text.to_s, replacement_text.to_s return self if [text, replacement_text].any? { |t| t.empty? } filter_object!(self, text, replacement_text) end
ignore!()
click to toggle source
ignored?()
click to toggle source
@return [Boolean] whether or not this HTTP interaction should be ignored. @see ignore!
# File lib/vcr/structs.rb, line 523 def ignored? !!@ignored end
Private Instance Methods
filter_hash!(hash, text, replacement_text)
click to toggle source
# File lib/vcr/structs.rb, line 553 def filter_hash!(hash, text, replacement_text) filter_object!(hash.values, text, replacement_text) hash.keys.each do |k| new_key = filter_object!(k.dup, text, replacement_text) hash[new_key] = hash.delete(k) unless k == new_key end end
filter_object!(object, text, replacement_text)
click to toggle source
# File lib/vcr/structs.rb, line 540 def filter_object!(object, text, replacement_text) if object.respond_to?(:gsub) object.gsub!(text, replacement_text) if object.include?(text) elsif Hash === object filter_hash!(object, text, replacement_text) elsif object.respond_to?(:each) # This handles nested arrays and structs object.each { |o| filter_object!(o, text, replacement_text) } end object end