Class: Webpack::Testing::FileServer
- Inherits:
-
Rack::Server
- Object
- Rack::Server
- Webpack::Testing::FileServer
- Defined in:
- lib/webpack/testing/file_server.rb
Instance Method Summary collapse
- #host ⇒ Object
- #host_with_port ⇒ Object
-
#initialize(root) ⇒ FileServer
constructor
A new instance of FileServer.
- #pid ⇒ Object
- #port ⇒ Object
- #run(timeout: 10) {|_self| ... } ⇒ Object
- #running? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(root) ⇒ FileServer
Returns a new instance of FileServer.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/webpack/testing/file_server.rb', line 10 def initialize(root) port = unused_port pid = File.("./tmp/rack-#{port}.pid") super( app: ::Rack::File.new(root), Host: default_host, Port: port, pid: pid, daemonize: true ) end |
Instance Method Details
#host ⇒ Object
22 23 24 |
# File 'lib/webpack/testing/file_server.rb', line 22 def host [:Host] end |
#host_with_port ⇒ Object
30 31 32 |
# File 'lib/webpack/testing/file_server.rb', line 30 def host_with_port "#{host}:#{port}" end |
#pid ⇒ Object
34 35 36 |
# File 'lib/webpack/testing/file_server.rb', line 34 def pid ::File.exist?([:pid]) ? ::File.read([:pid]).to_i : nil end |
#port ⇒ Object
26 27 28 |
# File 'lib/webpack/testing/file_server.rb', line 26 def port [:Port] end |
#run(timeout: 10) {|_self| ... } ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/webpack/testing/file_server.rb', line 45 def run(timeout: 10) Process.fork { start } unless running? wait timeout return unless block_given? yield self stop end |
#running? ⇒ Boolean
38 39 40 41 42 43 |
# File 'lib/webpack/testing/file_server.rb', line 38 def running? Socket.tcp(host, port).close true rescue Errno::ECONNREFUSED false end |
#stop ⇒ Object
55 56 57 58 59 60 |
# File 'lib/webpack/testing/file_server.rb', line 55 def stop return if pid.nil? Process.kill "SIGTERM", pid ::File.delete([:pid]) end |