Module: Akephalos::Filters
- Included in:
- Akephalos
- Defined in:
- lib/akephalos/configuration.rb
Instance Method Summary collapse
-
#filter(method, regex, options = {}) ⇒ Object
Defines a new filter to be tested by Akephalos::Filter when executing page requests.
-
#filters ⇒ Array
All defined filters.
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"
42 43 44 45 |
# File 'lib/akephalos/configuration.rb', line 42 def filter(method, regex, = {}) regex = Regexp.new(Regexp.escape(regex)) if regex.is_a?(String) filters << {:method => method, :filter => regex, :status => 200, :body => "", :headers => {}}.merge!() end |
#filters ⇒ Array
Returns all defined filters.
12 13 14 |
# File 'lib/akephalos/configuration.rb', line 12 def filters configuration[:filters] ||= [] end |