class ApiSim::Matchers::DynamicRequestMatcher

Attributes

default[R]
http_method[R]
matcher[R]
query[R]
response_generator[R]
route[R]

Public Class Methods

new(http_method:, route:, response_generator:, default: false, matcher: ALWAYS_TRUE_MATCHER) click to toggle source
# File lib/api_sim/matchers/dynamic_request_matcher.rb, line 11
def initialize(http_method:, route:, response_generator:, default: false, matcher: ALWAYS_TRUE_MATCHER)
  @matcher = matcher
  @route = Mustermann.new(route)
  @http_method = http_method
  @default = default
  @response_generator = response_generator
end

Public Instance Methods

matches?(request) click to toggle source
# File lib/api_sim/matchers/dynamic_request_matcher.rb, line 19
def matches?(request)
  matches_route_pattern?(request) && request.request_method == http_method && matcher.call(request)
end
readonly?() click to toggle source
# File lib/api_sim/matchers/dynamic_request_matcher.rb, line 27
def readonly?
  true
end
response(request) click to toggle source
# File lib/api_sim/matchers/dynamic_request_matcher.rb, line 23
def response(request)
  response_generator.call(SmartRequest.new(request, self))
end
to_s() click to toggle source
# File lib/api_sim/matchers/dynamic_request_matcher.rb, line 31
      def to_s
        <<-DOC.gsub(/^\s+/, '')
          #{http_method} #{route} -> DYNAMIC BASED ON REQUEST
        DOC
      end