Class: Brandish::Application::ServeCommand Private
- Inherits:
-
Object
- Object
- Brandish::Application::ServeCommand
- Includes:
- Commander::Methods
- Defined in:
- lib/brandish/application/serve_command.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The serve command. This builds, and then serves, an existing Brandish project. This watches the source. If it detects a change, it rebuilds.
Constant Summary collapse
- COMMAND_DESCRIPTION =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The description for the serve command.
"Builds, and serves, an existing Brandish project."
- DEFAULTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The default options for the serve command.
{ only: :all, show_build: false }.freeze
Class Method Summary collapse
-
.call(application, options) ⇒ void
private
Performs the serve command.
-
.define(application, command) ⇒ void
private
Defines the command on the given application.
Instance Method Summary collapse
-
#call ⇒ void
private
Performs the serve command.
-
#initialize(application, options) ⇒ ServeCommand
constructor
private
Initialize the serve command.
Constructor Details
#initialize(application, options) ⇒ ServeCommand
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize the serve command.
52 53 54 55 56 |
# File 'lib/brandish/application/serve_command.rb', line 52 def initialize(application, ) @application = application @options = DEFAULTS.merge() @port = @options.fetch(:port, (ENV["PORT"] || "3000").to_i) end |
Class Method Details
.call(application, options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Performs the serve command. This initializes the command, and calls #call.
39 40 41 42 |
# File 'lib/brandish/application/serve_command.rb', line 39 def self.call(application, ) puts "Running with options #{.inspect}..." new(application, ).call end |
.define(application, command) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Defines the command on the given application. This sets the important data information for the command, for use for the help output.
22 23 24 25 26 27 28 29 30 |
# File 'lib/brandish/application/serve_command.rb', line 22 def self.define(application, command) command.syntax = "branish serve" command.description = COMMAND_DESCRIPTION command.option "-p", "--port PORT", ::Integer, "The port to listen on" command.option "-o", "--only NAMES", [::String], "The forms to build" command.option "--verbose", "Whether or not to be verbose in the output" command.action { |_, o| call(application, o.__hash__) } end |
Instance Method Details
#call ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Performs the serve command. It first loads the configuration file, then calls #start_webserver, followed by #start_buildserver. Once both servers are setup, it calls #wait_on_servers.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/brandish/application/serve_command.rb', line 63 def call @configuration = @application.load_configuration_file say "=> Beginning serve..." start_webserver start_buildserver color "\r=> Ready and waiting! ", :erase_line, :green wait_on_servers rescue StandardError, ScriptError => e # Whenever we receive a general error, which only occurs while setup, # we complain, and pass up the exception. say_error "\n!> Received exception: #{e.class}: #{e.}" e.backtrace.each { |l| say_warning "\t-> in #{l}" } if @options[:trace] fail rescue SignalException, NoMemoryError, SystemExit, SystemStackError => e # Whenever we receive a signal, or an unrecoverable error, we kill # the servers and complain. These exceptions occur on the main thread, # and so we handle them here. say_warning "\n!> Received exception: #{e.class}: #{e.}" say_ok "\n-> Received termination, shutting down..." kill_webserver kill_buildserver end |