Class: VanilliServer
- Inherits:
-
Object
- Object
- VanilliServer
- Defined in:
- lib/vanilli/server.rb
Overview
Provides hooks for starting and stopping a vanilli server. Relies on the vanilli CLI API and therefore requires vanilli to be installed.
Instance Method Summary collapse
-
#initialize(port:, static_root: nil, static_include: [], static_exclude: [], static_default: 'index.html', log_level: 'warn') ⇒ VanilliServer
constructor
A new instance of VanilliServer.
-
#start(cwd: '.') ⇒ Object
Shells out to start vanilli.
-
#stop ⇒ Object
Stops the vanilli server by killing the process started when shelling out to start vanilli.
Constructor Details
#initialize(port:, static_root: nil, static_include: [], static_exclude: [], static_default: 'index.html', log_level: 'warn') ⇒ VanilliServer
Returns a new instance of VanilliServer.
7 8 9 10 11 12 13 14 |
# File 'lib/vanilli/server.rb', line 7 def initialize(port:, static_root: nil, static_include: [], static_exclude: [], static_default: 'index.html', log_level: 'warn') @static_root = static_root @static_default = static_default @static_include = JSON.generate(static_include) @static_exclude = JSON.generate(static_exclude) @port = port @log_level = log_level end |
Instance Method Details
#start(cwd: '.') ⇒ Object
Shells out to start vanilli
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vanilli/server.rb', line 17 def start(cwd: '.') @pid = spawn("vanilli --port #{@port} \ --logLevel=#{@log_level} \ --staticRoot=#{@static_root} \ --staticDefault=#{@static_default} \ --staticInclude='#{@static_include}' \ --staticExclude='#{@static_exclude}'", chdir: cwd) Timeout.timeout(3) do begin RestClient.get "http://localhost:#{@port}/_vanilli/ping" rescue sleep 0.1 retry end end self end |
#stop ⇒ Object
Stops the vanilli server by killing the process started when shelling out to start vanilli
39 40 41 42 43 44 45 |
# File 'lib/vanilli/server.rb', line 39 def stop if @pid Process.kill('KILL', @pid) Process.wait @pid end @pid = nil end |