Module: Akephalos::Filters

Included in:
Akephalos
Defined in:
lib/akephalos/configuration.rb

Instance Method Summary collapse

Instance Method Details

#filter(method, regex, options = {}) ⇒ Object

Defines a new filter to be tested by Akephalos::Filter when executing page requests. An HTTP method and a regex or string to match against the URL are required for defining a filter.

You can additionally pass the following options to define how the filtered request should respond:

:status       (defaults to 200)
:body         (defaults to "")
:headers      (defaults to {})

If we define a filter with no additional options, then, we will get an empty HTML response:

Akephalos.filter :post, "http://example.com"
Akephalos.filter :any, %r{http://.*\.com}

If you instead, say, wanted to simulate a failure in an external system, you could do this:

Akephalos.filter :post, "http://example.com",
  :status => 500, :body => "Something went wrong"

Parameters:

  • method (Symbol)

    the HTTP method to match

  • regex (RegExp, String)

    URL matcher

  • options (Hash) (defaults to: {})

    response values



42
43
44
45
# File 'lib/akephalos/configuration.rb', line 42

def filter(method, regex, options = {})
  regex = Regexp.new(Regexp.escape(regex)) if regex.is_a?(String)
  filters << {:method => method, :filter => regex, :status => 200, :body => "", :headers => {}}.merge!(options)
end

#filtersArray

Returns all defined filters.

Returns:

  • (Array)

    all defined filters



12
13
14
# File 'lib/akephalos/configuration.rb', line 12

def filters
  configuration[:filters] ||= []
end