Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware mutex class #1075

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Middleware mutex class #1075

wants to merge 5 commits into from

Conversation

technoweenie
Copy link
Member

@technoweenie technoweenie commented Nov 13, 2019

This extracts the Faraday::MiddlewareRegistry module functionality into a Faraday::ClassRegistry class. This allows us to make some better assumptions about how the class registry's internal vars are loaded.

TODO:

I also made a few small changes that may bite us later:

  1. Deprecated #load_middleware. It's the same as #lookup_middleware, except #lookup_middleware raises if it doesn't return anything. When deciding between ClassRegistry#lookup and #load, I went with #lookup since #load is an existing ruby method.

def lookup_middleware(key)
class_registry.lookup(key)
end
def load_middleware(key)
warn "Deprecated, use #{self}.lookup_middleware"
lookup_middleware(key)
end

  1. Deprecated #middleware_mutex and #fetch_middleware. Those should've been private originally. They're not used elsewhere in Faraday, but may be in use in an external lib or app. Pretty low chance though...

def middleware_mutex
warn "Deprecated, see #{self}.class_registry"
end
def fetch_middleware(_)
warn "Deprecated, see #{self}.class_registry"
end

  1. #register_middleware now complains if you try to change the autoload_path _after the ClassRegistry has been setup`. So, something like:
module Faraday
  class Adapter
    extend MiddlewareRegistry

    # first time, set 'path/to/adapters' as @autoload_path
    register_middleware 'path/to/adapters', foo: Foo

    # subsequent calls MUST ignore @autoload_path
    register_middleware bar: Bar

    # raises a warning: 
    # "Cannot change autoload_path of existing Faraday::Adapter.class_registry"
    register_middleware 'path/to/other-adapters', baz: Baz
  end
end

unless autoload_path.nil?
warn "Cannot change autoload_path of existing #{self}.class_registry"
end

@iMacTia iMacTia added the parked Parked for future label Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parked Parked for future
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants