Class: Spoonerize::Web::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/spoonerize/web/cli.rb

Overview

Command-line launcher for the web app.

Constant Summary collapse

DEFAULT_OPTIONS =

Server options used when no command-line overrides are passed.

Returns:

  • (Hash)
{
  host: Web.bind,
  port: Web.port
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ self

Create a web CLI launcher.

Parameters:

  • options (Array)

    Command-line arguments.



43
44
45
# File 'lib/spoonerize/web/cli.rb', line 43

def initialize(options)
  @options = DEFAULT_OPTIONS.merge(parse(options))
end

Instance Attribute Details

#optionsHash (readonly)

Parsed server options.

Returns:

  • (Hash)


35
36
37
# File 'lib/spoonerize/web/cli.rb', line 35

def options
  @options
end

Class Method Details

.execute(options = []) ⇒ nil

Starts the web app from command-line arguments.

Parameters:

  • options (Array) (defaults to: [])

Returns:

  • (nil)


27
28
29
# File 'lib/spoonerize/web/cli.rb', line 27

def self.execute(options = [])
  new(options).execute
end

Instance Method Details

#executenil

Starts the Sinatra web app.

Returns:

  • (nil)


51
52
53
# File 'lib/spoonerize/web/cli.rb', line 51

def execute
  Web.run!(bind: options[:host], port: options[:port])
end