http-mock-server 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/lib/http-mock-server.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 110e2a7871cb0e74b6f8fec9fb8e485624eb2352
|
4
|
+
data.tar.gz: 135d9cb6d537ef0e24b48ad7a3340ea653563925
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5ca95bb3fadc757e69c814e1be01d5d01fcc543d84073bd7f01cc64446c45b43ced75e32742ea2c7b86b7e5532604694c7d30bd575e5bb1c6a17cccb726ac5e
|
7
|
+
data.tar.gz: c9adf8da5670b10d9de7dee73f7559590f917bd76b0aeb9094a6ca1360a312a73045b0caa7b7c6d0bad98cd723327c2a644a0dffaa1c32681410f5a7176462da
|
data/README.md
CHANGED
@@ -20,10 +20,11 @@ Features:
|
|
20
20
|
|
21
21
|
```yml
|
22
22
|
config:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
namespace: '/api/v1' # prepend to every route
|
24
|
+
# no_cors: true # don't send CORS headers
|
25
|
+
port: 8080 # server port
|
26
|
+
# timeout: 10 # response timeout
|
27
|
+
verbose: true # shows request params
|
27
28
|
not_found:
|
28
29
|
body:
|
29
30
|
message: This is not the path you are looking for...
|
data/lib/http-mock-server.rb
CHANGED
@@ -10,6 +10,7 @@ $config = YAML.load File.read(CONFIG_FILE) rescue begin
|
|
10
10
|
exit 1
|
11
11
|
end
|
12
12
|
$config['config'] ||= {}
|
13
|
+
$config['config']['namespace'] ||= ''
|
13
14
|
$config['routes'] ||= []
|
14
15
|
|
15
16
|
class HttpMockServer < Sinatra::Base
|
@@ -40,7 +41,7 @@ class HttpMockServer < Sinatra::Base
|
|
40
41
|
break if method
|
41
42
|
end
|
42
43
|
if method
|
43
|
-
send method, rt[method] do
|
44
|
+
send method, $config['config']['namespace'] + rt[method] do
|
44
45
|
route = reload_route i
|
45
46
|
code = route['status'] || 200
|
46
47
|
log code, method.upcase, request.path
|
@@ -90,10 +91,9 @@ class HttpMockServer < Sinatra::Base
|
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
93
|
-
def interpolate(
|
94
|
-
|
95
|
-
|
96
|
-
string.gsub( /{(.*?)}/, '%s' ) % vars
|
94
|
+
def interpolate( input )
|
95
|
+
vars = input.to_s.scan( /{(.*?)}/ ).flatten.map{|t| eval(t)}
|
96
|
+
input.to_s.gsub( /{(.*?)}/, '%s' ) % vars
|
97
97
|
end
|
98
98
|
|
99
99
|
def reload_route( route_id )
|