Module: HTTPX::Registry

Included in:
Connection, IO, Plugins::Compression, Resolver, Transcoder
Defined in:
lib/httpx/registry.rb

Overview

Adds a general-purpose registry API to a class. It is designed to be a configuration-level API, i.e. the registry is global to the class and should be set on **boot time**.

It is used internally to associate tags with handlers.

## Register/Fetch

One is strongly advised to register handlers when creating the class.

There is an instance-level method to retrieve from the registry based on the tag:

class Server
  include HTTPX::Registry

  register "tcp", TCPHandler
  register "ssl", SSLHandlers
  ...

  def handle(uri)
    scheme = uri.scheme
    handler = registry(scheme) #=> TCPHandler
    handler.handle
  end
end

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Constant Summary collapse

Error =

Base Registry Error

Class.new(Error)

Class Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object



36
37
38
39
# File 'lib/httpx/registry.rb', line 36

def self.extended(klass)
  super
  klass.extend(ClassMethods)
end

.included(klass) ⇒ Object



41
42
43
44
45
# File 'lib/httpx/registry.rb', line 41

def self.included(klass)
  super
  klass.extend(ClassMethods)
  klass.__send__(:include, InstanceMethods)
end