Class: MockServer::Model::Expectation

Inherits:
Object
  • Object
show all
Includes:
UtilityMethods
Defined in:
lib/mockserver/model/expectation.rb

Overview

Expectation model

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UtilityMethods

#camelize, #camelized_hash, #parse_string_to_json, #symbolize_keys

Instance Attribute Details

#timesObject

Returns the value of attribute times.



26
27
28
# File 'lib/mockserver/model/expectation.rb', line 26

def times
  @times
end

Instance Method Details

#forward {|the| ... } ⇒ Expectation

Method to setup the request on the expectation object

Yield Parameters:

  • the (Forward)

    forward object that this expectation references

Returns:

  • (Expectation)

    this object according to the the builder pattern



69
70
71
72
73
74
75
# File 'lib/mockserver/model/expectation.rb', line 69

def forward(&_)
  if block_given?
    @forward ||= Forward.new
    yield @forward
  end
  @forward
end

#forward=(forward) ⇒ Object

Setter for forward

Parameters:

  • forward (Forward)

    a forward object



91
92
93
# File 'lib/mockserver/model/expectation.rb', line 91

def forward=(forward)
  @forward = Forward.new(forward)
end

#populate_from_payload(payload) ⇒ Object

Creates an expectation from a hash

Parameters:

  • payload (Hash)

    a hash representation of the expectation



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mockserver/model/expectation.rb', line 30

def populate_from_payload(payload)
  @request = payload[MockServer::HTTP_REQUEST]
  @request = Request.new(symbolize_keys(@request)) if @request

  @response = payload[MockServer::HTTP_RESPONSE]
  @response = Response.new(symbolize_keys(@response)) if @response

  @forward = payload[MockServer::HTTP_FORWARD]
  @forward = Forward.new(symbolize_keys(@forward)) if @forward

  @times = payload[MockServer::HTTP_TIMES]
  @times = Times.new(symbolize_keys(@times)) if @times
end

#request {|the| ... } ⇒ Expectation

Method to setup the request on the expectation object

Yield Parameters:

  • the (Request)

    request that this expectation references

Returns:

  • (Expectation)

    this object according to the the builder pattern



47
48
49
50
51
52
53
# File 'lib/mockserver/model/expectation.rb', line 47

def request(&_)
  if block_given?
    @request ||= Request.new
    yield @request
  end
  @request
end

#request=(request) ⇒ Object

Setter for request

Parameters:

  • request (Request)

    a request object



79
80
81
# File 'lib/mockserver/model/expectation.rb', line 79

def request=(request)
  @request = Request.new(request)
end

#response {|the| ... } ⇒ Expectation

Method to setup the response on the expectation object

Yield Parameters:

  • the (Response)

    response that this expectation references

Returns:

  • (Expectation)

    this object according to the the builder pattern



58
59
60
61
62
63
64
# File 'lib/mockserver/model/expectation.rb', line 58

def response(&_)
  if block_given?
    @response ||= Response.new
    yield @response
  end
  @response
end

#response=(response) ⇒ Object

Setter for response

Parameters:

  • response (Response)

    a response object



85
86
87
# File 'lib/mockserver/model/expectation.rb', line 85

def response=(response)
  @response = Response.new(response)
end

#to_hashHash

Convert to hash

Returns:

  • (Hash)

    the hash representation for this object



103
104
105
106
107
108
109
110
# File 'lib/mockserver/model/expectation.rb', line 103

def to_hash
  {
    MockServer::HTTP_REQUEST  => @request,
    MockServer::HTTP_RESPONSE => @response,
    MockServer::HTTP_FORWARD  => @forward,
    MockServer::HTTP_TIMES    => @times
  }
end

#to_json(*p) ⇒ String

Override to_json method

Returns:

  • (String)

    the json representation for this object



97
98
99
# File 'lib/mockserver/model/expectation.rb', line 97

def to_json(*p)
  to_hash.to_json(*p)
end