Class: Locomotive::Wagon::ServeCommand

Inherits:
Struct
  • Object
show all
Defined in:
lib/locomotive/wagon/commands/serve_command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options, shell) ⇒ ServeCommand

Returns a new instance of ServeCommand.



7
8
9
10
# File 'lib/locomotive/wagon/commands/serve_command.rb', line 7

def initialize(path, options, shell)
  super(path, options || {}, shell)
  @parent_id = nil
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



5
6
7
# File 'lib/locomotive/wagon/commands/serve_command.rb', line 5

def options
  @options
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



5
6
7
# File 'lib/locomotive/wagon/commands/serve_command.rb', line 5

def path
  @path
end

#shellObject

Returns the value of attribute shell

Returns:

  • (Object)

    the current value of shell



5
6
7
# File 'lib/locomotive/wagon/commands/serve_command.rb', line 5

def shell
  @shell
end

Class Method Details

.start(path, options = {}, shell) ⇒ Object



12
13
14
# File 'lib/locomotive/wagon/commands/serve_command.rb', line 12

def self.start(path, options = {}, shell)
  new(path, options, shell).start
end

.stop(path, force = false, shell) ⇒ Object



16
17
18
# File 'lib/locomotive/wagon/commands/serve_command.rb', line 16

def self.stop(path, force = false, shell)
  new(path, nil, shell).stop(force)
end

Instance Method Details

#startObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/locomotive/wagon/commands/serve_command.rb', line 20

def start
  # make sure a server is not running
  stop(true) if options[:force]

  # Steam is our rendering engine
  require_steam

  # in case the developer installed custom libs
  Locomotive::Wagon.require_misc_gems

  setup_signals

  show_start_message

  show_rack_middleware_stack if options[:debug]

  # if a page, a content type or any resources of the site is getting modified,
  # then the cache of Steam will be cleared.
  listen

  # let's start!
  begin
    server.start
  rescue NoMethodError # Prevent the NilClass error from Puma to be displayed
    nil
  end
end

#stop(force = false) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/locomotive/wagon/commands/serve_command.rb', line 48

def stop(force = false)
  unless File.exist?(server_pid_file)
    shell.say "No Wagon server is running.", :red
    return
  end

  pid = File.read(server_pid_file).to_i
  Process.kill('TERM', pid)

  shell.say "\nShutting down Wagon server"

  # make sure we wait enough for the server process to stop
  sleep(2) if force
end