Module: HTTPX::Registry::ClassMethods
- Defined in:
- lib/httpx/registry.rb
Overview
Class Methods
Instance Method Summary collapse
- #inherited(klass) ⇒ Object
-
#register(tag, handler) ⇒ Symbol, ...
The handler (if Symbol or String, it is assumed to be an autoloaded module, to be loaded later).
-
#registry(tag = nil) ⇒ Symbol, ...
The corresponding handler (if Symbol or String, will assume it referes to an autoloaded module, and will load-and-return it).
Instance Method Details
#inherited(klass) ⇒ Object
49 50 51 52 |
# File 'lib/httpx/registry.rb', line 49 def inherited(klass) super klass.instance_variable_set(:@registry, @registry.dup) end |
#register(tag, handler) ⇒ Symbol, ...
Returns the handler (if Symbol or String, it is assumed to be an autoloaded module, to be loaded later).
77 78 79 |
# File 'lib/httpx/registry.rb', line 77 def register(tag, handler) registry[tag] = handler end |
#registry(tag = nil) ⇒ Symbol, ...
Returns the corresponding handler (if Symbol or String, will assume it referes to an autoloaded module, and will load-and-return it).
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/httpx/registry.rb', line 58 def registry(tag = nil) @registry ||= {} return @registry if tag.nil? handler = @registry.fetch(tag) raise(Error, "#{tag} is not registered in #{self}") unless handler case handler when Symbol, String const_get(handler) else handler end end |