Sha256: 3ae52992674404cba6cbfd1ecd58e65c6d86b5a301796fee4dc995ddf3dffb89

Contents?: true

Size: 1.53 KB

Versions: 37

Compression:

Stored size: 1.53 KB

Contents

module Akephalos

  @configuration = {}

  class << self
    # @return [Hash] the configuration
    attr_accessor :configuration
  end

  module Filters
    # @return [Array] all defined filters
    def filters
      configuration[:filters] ||= []
    end

    # 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"
    #
    # @param [Symbol] method the HTTP method to match
    # @param [RegExp, String] regex URL matcher
    # @param [Hash] options response values
    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
  end

  extend Filters
end

Version data entries

37 entries across 37 versions & 7 rubygems

Version Path
akephalos2-2.1.3-java lib/akephalos/configuration.rb
akephalos2-2.1.3 lib/akephalos/configuration.rb
akephalos2-2.1.2-java lib/akephalos/configuration.rb
akephalos2-2.1.2 lib/akephalos/configuration.rb
akephalos2-2.1.1.2-java lib/akephalos/configuration.rb
akephalos2-2.1.1.2 lib/akephalos/configuration.rb
akephalos2-stable-2.1.1.1 lib/akephalos/configuration.rb
akephalos2-2.1.1.1-java lib/akephalos/configuration.rb
akephalos2-2.1.1.1 lib/akephalos/configuration.rb
akephalos2-2.1.1-java lib/akephalos/configuration.rb
akephalos2-2.1.1 lib/akephalos/configuration.rb
akephalos2-2.1.0-java lib/akephalos/configuration.rb
akephalos2-2.1.0 lib/akephalos/configuration.rb
akephalos2-2.0.9-java lib/akephalos/configuration.rb
akephalos2-2.0.9 lib/akephalos/configuration.rb
akephalos2-2.0.8.1-java lib/akephalos/configuration.rb
akephalos2-2.0.8.1 lib/akephalos/configuration.rb
akephalos2-2.0.8-java lib/akephalos/configuration.rb
akephalos2-2.0.8 lib/akephalos/configuration.rb
akephalos2-2.0.7-java lib/akephalos/configuration.rb