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.
-
#response_generator ⇒ Object
readonly
Returns the value of attribute response_generator.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
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.
9 10 11 12 13 14 15 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 9 def initialize(http_method:, route:, response_generator:, default: false, matcher: ALWAYS_TRUE_MATCHER) @matcher = matcher @route = route @http_method = http_method @default = default @response_generator = response_generator end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
7 8 9 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 7 def default @default end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
7 8 9 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 7 def http_method @http_method end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
7 8 9 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 7 def matcher @matcher end |
#response_generator ⇒ Object (readonly)
Returns the value of attribute response_generator.
7 8 9 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 7 def response_generator @response_generator end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
7 8 9 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 7 def route @route end |
Instance Method Details
#matches?(request) ⇒ Boolean
17 18 19 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 17 def matches?(request) request.path == route && request.request_method == http_method && matcher.call(request) end |
#readonly? ⇒ Boolean
25 26 27 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 25 def readonly? true end |
#response(request) ⇒ Object
21 22 23 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 21 def response(request) response_generator.call(request) end |
#to_s ⇒ Object
29 30 31 32 33 |
# File 'lib/api_sim/matchers/dynamic_request_matcher.rb', line 29 def to_s <<-DOC.gsub(/^\s+/, '') #{http_method} #{route} -> DYNAMIC BASED ON REQUEST DOC end |