Class: Dupe::Network
- Inherits:
-
Object
- Object
- Dupe::Network
- Includes:
- RestValidation
- Defined in:
- lib/superdupe/log.rb,
lib/superdupe/mock.rb,
lib/superdupe/mock.rb,
lib/superdupe/mock.rb,
lib/superdupe/mock.rb,
lib/superdupe/mock.rb,
lib/superdupe/network.rb,
lib/superdupe/rest_validation.rb
Overview
:nodoc:
Defined Under Namespace
Modules: RestValidation Classes: DeleteMock, GetMock, Log, Mock, PostMock, PutMock, RequestNotFoundError, UnknownRestVerbError
Constant Summary collapse
- VERBS =
:nodoc:
[:get, :post, :put, :delete]
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#mocks ⇒ Object
readonly
Returns the value of attribute mocks.
Instance Method Summary collapse
- #define_service_mock(verb, url_pattern, response_proc = nil) ⇒ Object
-
#initialize ⇒ Network
constructor
A new instance of Network.
- #request(verb, url, body = nil) ⇒ Object
Methods included from RestValidation
Constructor Details
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
7 8 9 |
# File 'lib/superdupe/network.rb', line 7 def log @log end |
#mocks ⇒ Object (readonly)
Returns the value of attribute mocks.
7 8 9 |
# File 'lib/superdupe/network.rb', line 7 def mocks @mocks end |
Instance Method Details
#define_service_mock(verb, url_pattern, response_proc = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/superdupe/network.rb', line 20 def define_service_mock(verb, url_pattern, response_proc=nil) validate_request_type verb case verb when :get GetMock.new(url_pattern, response_proc).tap do |mock| @mocks[verb] << mock end when :post PostMock.new(url_pattern, response_proc).tap do |mock| @mocks[verb].unshift mock end when :put PutMock.new(url_pattern, response_proc).tap do |mock| @mocks[verb].unshift mock end when :delete DeleteMock.new(url_pattern, response_proc).tap do |mock| @mocks[verb].unshift mock end else raise StandardError, "Dupe does not support mocking #{verb.to_s.upcase} requests." end end |
#request(verb, url, body = nil) ⇒ Object
15 16 17 18 |
# File 'lib/superdupe/network.rb', line 15 def request(verb, url, body=nil) validate_request_type verb match(verb, url).mocked_response(url, body) end |