Class: HttpStub::Models::Stub

Inherits:
Object
  • Object
show all
Defined in:
lib/http_stub/models/stub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Stub

Returns a new instance of Stub.



8
9
10
11
12
13
14
# File 'lib/http_stub/models/stub.rb', line 8

def initialize(options)
  @options = options
  @uri = HttpStub::Models::StubUri.new(options["uri"])
  @headers = HttpStub::Models::StubHeaders.new(options["headers"])
  @parameters = HttpStub::Models::StubParameters.new(options["parameters"])
  @response = HttpStub::Models::Response.new(options["response"])
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/http_stub/models/stub.rb', line 6

def headers
  @headers
end

#parametersObject (readonly)

Returns the value of attribute parameters.



6
7
8
# File 'lib/http_stub/models/stub.rb', line 6

def parameters
  @parameters
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/http_stub/models/stub.rb', line 6

def response
  @response
end

#uriObject (readonly)

Returns the value of attribute uri.



6
7
8
# File 'lib/http_stub/models/stub.rb', line 6

def uri
  @uri
end

Instance Method Details

#methodObject



23
24
25
# File 'lib/http_stub/models/stub.rb', line 23

def method
  @options["method"]
end

#satisfies?(request) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/http_stub/models/stub.rb', line 16

def satisfies?(request)
  @uri.match?(request) &&
      method.downcase == request.request_method.downcase &&
      @headers.match?(request) &&
      @parameters.match?(request)
end

#to_sObject



27
28
29
# File 'lib/http_stub/models/stub.rb', line 27

def to_s
  @options.to_s
end