anymock 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/anymock.rb +28 -11
- data/lib/anymock/cli.rb +5 -1
- data/lib/anymock/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f33ecb35b1a6474cb58b63fc5a35a6f89b84a7e2cdb91f93e86ec216aa8279d2
|
4
|
+
data.tar.gz: f58df06d1d72f8c5cd62abdccca38003da37a18a17da1ede18f5123f391f97e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de404d0ab4b656c531eeb7b51b7c3a5792fa33c213ebc5ac28d50ea9c9f0e1413a66ad774f5d47b6328faa3d472642a607b9124f4e041a09522b9ac3eddc2d4d
|
7
|
+
data.tar.gz: 4ba439ae5e9f186b0cd278c536398114e1c2598a28e30b12b9a750972b122d8fb1b11dd4f2a539239506c66d10606b47a4ddf693f3dc00f3146b57561b01d7db
|
data/lib/anymock.rb
CHANGED
@@ -2,6 +2,7 @@ require "anymock/version"
|
|
2
2
|
require "anymock/cli"
|
3
3
|
require "webrick"
|
4
4
|
require "json"
|
5
|
+
require "logger"
|
5
6
|
|
6
7
|
module Anymock
|
7
8
|
class Server
|
@@ -12,12 +13,18 @@ module Anymock
|
|
12
13
|
@address = opts[:address]
|
13
14
|
@port = opts[:port]
|
14
15
|
@response = opts[:response]
|
16
|
+
@log = opts[:log]
|
15
17
|
@mirror = opts[:mirror]
|
18
|
+
@json = opts[:json]
|
16
19
|
end
|
17
20
|
|
18
21
|
def start
|
19
22
|
server.mount_proc '/' do |req, res|
|
20
|
-
|
23
|
+
output_params = {
|
24
|
+
path: req.path,
|
25
|
+
method: req.request_method,
|
26
|
+
query: req.query
|
27
|
+
}
|
21
28
|
res.status = status_code(req.request_method)
|
22
29
|
if @response
|
23
30
|
res.body = @response
|
@@ -26,20 +33,22 @@ module Anymock
|
|
26
33
|
else
|
27
34
|
res.status = 204
|
28
35
|
end
|
29
|
-
output
|
36
|
+
output output_params.merge({ response: res.body })
|
30
37
|
end
|
31
38
|
server.start
|
32
39
|
end
|
33
40
|
|
34
|
-
def output(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
def output(params)
|
42
|
+
if @json
|
43
|
+
logger.info params.to_json
|
44
|
+
else
|
45
|
+
logger.info '----'
|
46
|
+
%i(path method query response).each do |n|
|
47
|
+
logger.info "#{n}:"
|
48
|
+
logger.info params[n]
|
49
|
+
end
|
50
|
+
logger.info '----'
|
51
|
+
end
|
43
52
|
end
|
44
53
|
|
45
54
|
private
|
@@ -55,6 +64,14 @@ module Anymock
|
|
55
64
|
end
|
56
65
|
end
|
57
66
|
|
67
|
+
def logger
|
68
|
+
@logger ||= Logger.new(log)
|
69
|
+
end
|
70
|
+
|
71
|
+
def log
|
72
|
+
@log || STDOUT
|
73
|
+
end
|
74
|
+
|
58
75
|
def server
|
59
76
|
@server ||= WEBrick::HTTPServer.new({
|
60
77
|
DocumentRoot: document_root,
|
data/lib/anymock/cli.rb
CHANGED
@@ -8,7 +8,9 @@ module Anymock
|
|
8
8
|
option :a, type: :string, default: 'localhost'
|
9
9
|
option :p, type: :string, default: '8080'
|
10
10
|
option :r, type: :string, default: nil
|
11
|
+
option :l, type: :string
|
11
12
|
option :m, type: :boolean, default: false
|
13
|
+
option :j, type: :boolean, default: false
|
12
14
|
|
13
15
|
desc "start", "start mock server"
|
14
16
|
|
@@ -28,7 +30,9 @@ module Anymock
|
|
28
30
|
address: options[:a],
|
29
31
|
port: options[:p],
|
30
32
|
response: options[:r],
|
31
|
-
|
33
|
+
log: options[:l],
|
34
|
+
mirror: options[:m],
|
35
|
+
json: options[:j]
|
32
36
|
}
|
33
37
|
end
|
34
38
|
end
|
data/lib/anymock/version.rb
CHANGED