Class: MockServer::Playback

Inherits:
Object
  • Object
show all
Includes:
Store, Utils
Defined in:
lib/mock_server/playback.rb

Instance Method Summary collapse

Methods included from Store

#mock_server_options_merge, #mock_server_options_read, #mock_server_options_write

Constructor Details

#initialize(app, opt = {}) ⇒ Playback

Returns a new instance of Playback.


16
17
18
19
# File 'lib/mock_server/playback.rb', line 16

def initialize(app, opt = {})
  @app = app
  @options = mock_server_options_merge(opt)
end

Instance Method Details

#call(env) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mock_server/playback.rb', line 21

def call(env)
  @options = self.mock_server_options_read

  verbose(env) if @options[:verbose]
  return @app.call(env) unless matchable_request?(env)

  @request = Rack::Request.new(env)
  @options[:requests_stack] << @request.path
  @data = load_data

  response = build_response
  self.mock_server_options_write(@options)
  response
end