class MiddleSquid::Adapter

Base class for MiddleSquid's adapters. Subclasses should call {#handle} when they have received and parsed a request.

@abstract Subclass and override {#output} to implement a custom adapter.

Attributes

handler[RW]

Returns whatever was passed to {Builder#run}.

@return [#call]

Public Class Methods

new(options = {}) click to toggle source

Returns a new instance of Adapter. Use {Builder#use} instead.

# File lib/middle_squid/adapter.rb, line 14
def initialize(options = {})
  @options = options
end

Public Instance Methods

handle(url, extras = []) click to toggle source

Execute the user handler (see {#handler}) and calls #output.

@param url <String> string representation of the url to be processed @param extras <Array> extra data to pass to the user's handler

# File lib/middle_squid/adapter.rb, line 22
def handle(url, extras = [])
  uri = MiddleSquid::URI.parse url
  raise InvalidURIError, "invalid URL received: '#{url}'" if !uri || !uri.host

  action, options = catch :action do
    @handler.call uri, extras
    throw :action, [:accept, {}]
  end

  output action, options
end
output(action, options) click to toggle source

Pass an action to an underlying software.

accept

(no options)

redirect

Options:

  • status [Fixnum]

  • url [String]

replace

Options:

  • url [String]

@param action [Symbol] @param options [Hash]

# File lib/middle_squid/adapter.rb, line 50
def output(action, options)
  raise NotImplementedError
end