Class: HttpStub::Server::Stub::Match::Rules

Inherits:
Object
  • Object
show all
Defined in:
lib/http_stub/server/stub/match/rules.rb

Constant Summary collapse

EMPTY =
self.new(uri: "", method: "", headers: {}, parameters: {}, body: "").freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Rules

Returns a new instance of Rules.


10
11
12
13
14
15
16
# File 'lib/http_stub/server/stub/match/rules.rb', line 10

def initialize(args)
  @uri        = HttpStub::Server::Stub::Match::Rule::Uri.new(args[:uri])
  @method     = HttpStub::Server::Stub::Match::Rule::Method.new(args[:method])
  @headers    = HttpStub::Server::Stub::Match::Rule::Headers.new(args[:headers])
  @parameters = HttpStub::Server::Stub::Match::Rule::Parameters.new(args[:parameters])
  @body       = HttpStub::Server::Stub::Match::Rule::Body.create(args[:body])
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body


8
9
10
# File 'lib/http_stub/server/stub/match/rules.rb', line 8

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers


8
9
10
# File 'lib/http_stub/server/stub/match/rules.rb', line 8

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method


8
9
10
# File 'lib/http_stub/server/stub/match/rules.rb', line 8

def method
  @method
end

#parametersObject (readonly)

Returns the value of attribute parameters


8
9
10
# File 'lib/http_stub/server/stub/match/rules.rb', line 8

def parameters
  @parameters
end

#uriObject (readonly)

Returns the value of attribute uri


8
9
10
# File 'lib/http_stub/server/stub/match/rules.rb', line 8

def uri
  @uri
end

Instance Method Details

#matches?(request, logger) ⇒ Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/http_stub/server/stub/match/rules.rb', line 20

def matches?(request, logger)
  [ @uri, @method, @headers, @parameters, @body ].all? { |matcher| matcher.matches?(request, logger) }
end

#to_json(*args) ⇒ Object


24
25
26
# File 'lib/http_stub/server/stub/match/rules.rb', line 24

def to_json(*args)
  { uri: @uri, method: @method, headers: @headers, parameters: @parameters, body: @body }.to_json(*args)
end