nec_mock_server 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/nec_mock_server/mock_server.rb +14 -1
- data/lib/nec_mock_server/mock_server_starter.rb +13 -11
- data/lib/nec_mock_server/version.rb +1 -1
- data/lib/nec_mock_server.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e38889970e4f40ae0784f58887606ae485242d0
|
4
|
+
data.tar.gz: 867b609df99b9cbf44826b31c96700b4efd83dec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2273f26d4446264b71f90917691f280142f7db4bbf2b7f36f0d9df14e6ebc091ac362c93b4d355d9dc5e2d84f63ce44ecce4b763ef1e08bb9f5052c5331def8
|
7
|
+
data.tar.gz: 7ba99dc529917411d2245eb4b6b0620da265380bc157918ab3dfbf2874f303a9ae6d7923fa3ff858d90349ed4f6bff5075ae0fcd59c48ba8c819ae5173daf081
|
@@ -168,8 +168,10 @@ module NEC
|
|
168
168
|
case parts[:resource]
|
169
169
|
when "/", ""
|
170
170
|
home
|
171
|
+
when "/exception"
|
172
|
+
exception("Application exception.")
|
171
173
|
when "/error"
|
172
|
-
error("
|
174
|
+
error("Server exception.")
|
173
175
|
else
|
174
176
|
not_found(parts[:resource])
|
175
177
|
end
|
@@ -223,6 +225,17 @@ module NEC
|
|
223
225
|
prepare_response_data(500, headers, body)
|
224
226
|
end
|
225
227
|
|
228
|
+
###
|
229
|
+
# The method represent base server error response, 400 Internal Server Error
|
230
|
+
#
|
231
|
+
# @param [Object] body Body of response
|
232
|
+
# @param [Hash] headers Headers of response
|
233
|
+
#
|
234
|
+
# @return [Array] response_data
|
235
|
+
def exception(body, headers = DEFAULT_HEADER)
|
236
|
+
prepare_response_data(400, headers, body)
|
237
|
+
end
|
238
|
+
|
226
239
|
private
|
227
240
|
|
228
241
|
###
|
@@ -9,34 +9,36 @@ module NEC
|
|
9
9
|
# @param [String] sub_app_dir_path
|
10
10
|
# @param [Hash] opts
|
11
11
|
# @option opts [String] :run_scrip_name Default is #RUN_SCRIPT_NAME
|
12
|
+
# @option opts [Fixnum] :port
|
12
13
|
def initialize(sub_app_dir_path, opts = {})
|
13
14
|
@path = File.expand_path(sub_app_dir_path, File.dirname(__FILE__))
|
14
15
|
@run_scrip_name = opts.fetch(:run_scrip_name) {RUN_SCRIPT_NAME}
|
16
|
+
@port = opts[:port]
|
15
17
|
end
|
16
18
|
|
17
19
|
###
|
18
20
|
# The method start another sub application by defined path
|
19
21
|
# Sub app will be started in new command line with irb
|
20
|
-
#
|
21
22
|
def run!
|
22
|
-
|
23
|
-
end
|
23
|
+
return if @port && already_run?
|
24
24
|
|
25
|
-
|
26
|
-
# The method terminate exists thread of sub app
|
27
|
-
def stop
|
28
|
-
warn('! Method has no function implementation !')
|
29
|
-
# fixme how to stop thread with cmd window | some process kill by pid ...
|
30
|
-
@thread.terminate if @thread
|
25
|
+
create_threat
|
31
26
|
end
|
32
27
|
|
33
28
|
private
|
34
29
|
|
30
|
+
def already_run?
|
31
|
+
begin
|
32
|
+
Net::HTTP.get(URI("http://localhost:#{@port}"))
|
33
|
+
return true
|
34
|
+
rescue Errno::ECONNREFUSED
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
35
39
|
###
|
36
40
|
# The method create new thread for sub app and start it in new cmd window.
|
37
41
|
def create_threat
|
38
|
-
stop
|
39
|
-
|
40
42
|
@thread = Thread.new {
|
41
43
|
system("cd #{@path} && start irb -I . -r #{@run_scrip_name}")
|
42
44
|
}
|
data/lib/nec_mock_server.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nec_mock_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marek Filteš
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|