Class: Anymock::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/anymock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Server

Returns a new instance of Server.



10
11
12
13
14
15
# File 'lib/anymock.rb', line 10

def initialize(opts = {})
  @document_root = opts[:document_root]
  @address = opts[:address]
  @port = opts[:port]
  @mirror = opts[:mirror]
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



8
9
10
# File 'lib/anymock.rb', line 8

def address
  @address
end

#document_rootObject

Returns the value of attribute document_root.



8
9
10
# File 'lib/anymock.rb', line 8

def document_root
  @document_root
end

#portObject

Returns the value of attribute port.



8
9
10
# File 'lib/anymock.rb', line 8

def port
  @port
end

Instance Method Details

#output(body) ⇒ Object



26
27
28
29
30
31
# File 'lib/anymock.rb', line 26

def output(body)
  puts "response:"
  puts "----"
  puts body
  puts "----"
end

#startObject



17
18
19
20
21
22
23
24
# File 'lib/anymock.rb', line 17

def start
  server.mount_proc '/' do |req, res|
    body = { req.request_method => req.query }.to_json
    res.body = body
    output body if @mirror
  end
  server.start
end