Class: MiddleSquid::Adapter Abstract

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

Overview

This class is abstract.

Subclass and override #output to implement a custom adapter.

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

Direct Known Subclasses

MiddleSquid::Adapters::Squid

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Adapter

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



14
15
16
# File 'lib/middle_squid/adapter.rb', line 14

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#handler#call

Returns whatever was passed to Builder#run.

Returns:

  • (#call)


10
11
12
# File 'lib/middle_squid/adapter.rb', line 10

def handler
  @handler
end

Instance Method Details

#handle(url, extras = []) ⇒ Object

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

Parameters:

  • url (String)

    string representation of the url to be processed

  • extras (Array) (defaults to: [])

    extra data to pass to the user’s handler

Raises:



22
23
24
25
26
27
28
29
30
31
32
# 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) ⇒ Object

Pass an action to an underlying software.

accept

(no options)

redirect

Options:

  • status [Fixnum]

  • url [String]

replace

Options:

  • url [String]

Parameters:

  • action (Symbol)
  • options (Hash)

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/middle_squid/adapter.rb', line 50

def output(action, options)
  raise NotImplementedError
end