Class: Yext::Api::Utils::Middleware::UriCleanup

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/yext/api/utils/middleware/uri_cleanup.rb

Overview

Faraday Middleware for cleaning up after Spyke.

I consider this a primary failing of Spyke. The use of a global “current_scope” and associations being stored in instance variables that are re-used in every single use of the association creates the potential and reality of leaks between calls because scopes don’t represent a filter as much as they represent the class itself.

Because of this and because there aren’t normal hooks on the models, I had to figure out a way to cleanup and reset associations between calls in a reliable manner.

Because we’re using Faraday, I am using Faraday middleware to hook into the API call and after we get a response, making a call on the class associated with the call that was made and telling that class to clean itself up.

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/yext/api/utils/middleware/uri_cleanup.rb', line 21

def call(env)
  @app.call(env).on_complete do |_environment|
    reset_class_uri(env)

    env.response
  end
end