Class: Tom::Merger

Inherits:
Object
  • Object
show all
Defined in:
lib/merger.rb

Overview

Please see the README for examples on how to use this.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.register_route(*args) ⇒ Object

Registers a route with the request dispatcher so that this classes subclass gets called when a request is made. One that matches the route.

The route can be a string, but it becomes a regular expression in here. When matching in order to find a merger for a request, the first one matching wins.

Parameters:

  • route (String)

    The route this Merger should respond to.

  • methods (Array<Symbol>)

    Optional array of methods that this Merger is listening to. It defaults to all (‘:head`, `:get`, `:put`, `:post`, `:delete`)



21
22
23
24
25
# File 'lib/merger.rb', line 21

def self.register_route(*args)
  route = args[0]
  methods = args[1..-1]
  Tom::Routes.register(route: /#{route}/, merger: self, methods: methods)
end

Instance Method Details

#merge(env, responses) ⇒ Array

When the request dispatcher made all the requests, it will call the merge method of the subclass with the responses as a hash in the form

Parameters:

  • env (Array)

    The incoming (original request) rack env object

  • responses (Hash)

    Replies from all Adapters that got triggered by route and method, e.g. ‘{ MyAdapter: rack_env, MyOtherAdapter: other_env }`

Returns:

  • (Array)

    A rack response (for example, something like [200, {}, “body”])



38
39
40
# File 'lib/merger.rb', line 38

def merge(env, responses)
  raise "Subclass, implement #merge(env, responses)!"
end