Class: Anymock::Server
- Inherits:
-
Object
- Object
- Anymock::Server
- Defined in:
- lib/anymock.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#document_root ⇒ Object
Returns the value of attribute document_root.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Server
constructor
A new instance of Server.
- #output(body) ⇒ Object
- #start ⇒ Object
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
#address ⇒ Object
Returns the value of attribute address.
8 9 10 |
# File 'lib/anymock.rb', line 8 def address @address end |
#document_root ⇒ Object
Returns the value of attribute document_root.
8 9 10 |
# File 'lib/anymock.rb', line 8 def document_root @document_root end |
#port ⇒ Object
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 |
#start ⇒ Object
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 |