Class: ApiSim::Matchers::DynamicRequestMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- ApiSim::Matchers::DynamicRequestMatcher
- Defined in:
- lib/api_sim/matchers/dynamic_request_matcher.rb
Constant Summary
Constants inherited from BaseMatcher
BaseMatcher::ALWAYS_TRUE_MATCHER, BaseMatcher::DEFAULT_RACK_RESPONSE
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#response_generator ⇒ Object
readonly
Returns the value of attribute response_generator.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Attributes inherited from BaseMatcher
Instance Method Summary collapse
-
#initialize(http_method:, route:, response_generator:, default: false, matcher: ALWAYS_TRUE_MATCHER) ⇒ DynamicRequestMatcher
constructor
A new instance of DynamicRequestMatcher.
- #matches?(request) ⇒ Boolean
- #readonly? ⇒ Boolean
- #response(request) ⇒ Object
- #to_s ⇒ Object
Methods inherited from BaseMatcher
#custom_matcher?, #match_on_body?, #overridden!, #overridden?, #record_request, #requests, #reset!
Constructor Details
#initialize(http_method:, route:, response_generator:, default: false, matcher: ALWAYS_TRUE_MATCHER) ⇒ DynamicRequestMatcher
Returns a new instance of DynamicRequestMatcher.
11 12 13 14 15 16 17 |
# 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 |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
9 10 11 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 9 def default @default end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
9 10 11 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 9 def http_method @http_method end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
9 10 11 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 9 def matcher @matcher end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
9 10 11 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 9 def query @query end |
#response_generator ⇒ Object (readonly)
Returns the value of attribute response_generator.
9 10 11 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 9 def response_generator @response_generator end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
9 10 11 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 9 def route @route end |
Instance Method Details
#matches?(request) ⇒ Boolean
19 20 21 |
# 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? ⇒ Boolean
27 28 29 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 27 def readonly? true end |
#response(request) ⇒ Object
23 24 25 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 23 def response(request) response_generator.call(SmartRequest.new(request, self)) end |
#to_s ⇒ Object
31 32 33 34 35 |
# 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 |