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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32733cc3a81acf9b3e934ee6503c064b3ba08865
4
- data.tar.gz: f1409ddd38ed3950352a0313435525efc6ae1f6e
3
+ metadata.gz: 1e38889970e4f40ae0784f58887606ae485242d0
4
+ data.tar.gz: 867b609df99b9cbf44826b31c96700b4efd83dec
5
5
  SHA512:
6
- metadata.gz: fe2703632cc31075b99dde43c690a2e86ae46b57a1b57cee7775457c33e650709cc2d200f594b207ee546d595a149af3e3e7896d16f678d641ce8aa4516d7a5c
7
- data.tar.gz: 86e1921914c41bae9d8097dad9cc162746c9fd31fc2b762a3ae0493b4b1be7187774bb5f12cb0585fa358435d1064b65763a8e7277451ddf69d414523912b2ef
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("Application exception")
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
- create_threat
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
  }
@@ -1,3 +1,3 @@
1
1
  module NECMockServer
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -2,6 +2,7 @@ require 'rack'
2
2
  require 'rack/server'
3
3
  require 'json'
4
4
  require 'fileutils'
5
+ require 'net/http'
5
6
 
6
7
  module NEC
7
8
 
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.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-01-25 00:00:00.000000000 Z
11
+ date: 2018-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler