Class: Endpointer::ResponseSubstitutioner

Inherits:
Object
  • Object
show all
Defined in:
lib/endpointer/response_substitutioner.rb

Instance Method Summary collapse

Instance Method Details

#substitute(request_body, response_body, substitutions) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/endpointer/response_substitutioner.rb', line 4

def substitute(request_body, response_body, substitutions)
  return response_body if substitutions.nil?

  substitutions.inject(response_body) do |output, substitution|
    value_to_use = get_value_for(request_body, substitution.fetch('from_request'))
    value_to_replace = get_value_for(response_body, substitution.fetch('to_response'))
    output.gsub(value_to_replace, value_to_use)
  end
end