Module: Tom::Routes
- Defined in:
- lib/tom/routes.rb
Overview
Takes care of registering adapters and mergers for routes, and then matching routes and methods to adapters and mergers.
Class Method Summary collapse
-
.adapters ⇒ Hash
See what Routes.register_adapter returns.
-
.mergers ⇒ Hash
See what Routes.register_merger returns.
- .register(opts) ⇒ Hash
-
.register_adapter(opts) ⇒ Hash
Registers an Adapter for a given route and request method.
-
.register_merger(opts) ⇒ Hash
Registers a Merger for a given route and request method.
Class Method Details
.adapters ⇒ Hash
Returns See what register_adapter returns.
68 69 70 |
# File 'lib/tom/routes.rb', line 68 def self.adapters @adapters end |
.mergers ⇒ Hash
Returns See what register_merger returns.
73 74 75 |
# File 'lib/tom/routes.rb', line 73 def self.mergers @mergers end |
.register(opts) ⇒ Hash
Registers a opts or opts for the given opts.
This method should not be called directly in your app, you would use Adapter.register_route or Merger.register_route in your subclass of Adapter or Merger
23 24 25 26 27 |
# File 'lib/tom/routes.rb', line 23 def self.register(opts) return register_adapter(opts) if opts[:adapter] return register_merger(opts) if opts[:merger] raise "You need to supply opts[:adapter] or opts[:merger]" end |
.register_adapter(opts) ⇒ Hash
Registers an Adapter for a given route and request method
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tom/routes.rb', line 39 def self.register_adapter(opts) validate_type(opts[:adapter], Adapter) methods = get_methods(opts) @adapters ||= default_methods_hash methods.each do |method| @adapters[method][opts[:route]] ||= [] @adapters[method][opts[:route]] << opts[:adapter] end @adapters end |
.register_merger(opts) ⇒ Hash
Registers a Merger for a given route and request method
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tom/routes.rb', line 56 def self.register_merger(opts) validate_type(opts[:merger], Merger) methods = get_methods(opts) @mergers ||= default_methods_hash methods.each do |method| @mergers[method][opts[:route]] ||= [] @mergers[method][opts[:route]] << opts[:merger] end @mergers end |