Class: RightDevelop::Commands::Server

Inherits:
Object
  • Object
show all
Includes:
RightSupport::Log::Mixin
Defined in:
lib/right_develop/commands/server.rb

Defined Under Namespace

Classes: PlainFormatter

Constant Summary collapse

CONFIG_CLASS =
::RightDevelop::Testing::Server::MightApi::Config
MODES =
CONFIG_CLASS::VALID_MODES
DEFAULT_SEND_TO =

for display in help message

'run a new instance of service from current shell'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode, options) ⇒ Server

Returns a new instance of Server.

Parameters:

  • mode (Symbol)

    one of :prune or :tickets

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • :root_dir (String)

    for config and fixtures.

  • :ruby_version (String)

    to select with rbenv when running server

  • :debug (String)

    is true for debug-level logging



98
99
100
101
102
103
104
105
106
# File 'lib/right_develop/commands/server.rb', line 98

def initialize(mode, options)
  logger = ::Logger.new(STDOUT)
  logger.level = options[:debug] ? ::Logger::DEBUG : ::Logger::WARN
  logger.formatter = PlainFormatter.new
  ::RightSupport::Log::Mixin.default_logger = logger

  @mode = mode
  @options = options
end

Class Method Details

.createObject

Parse command-line options and create a Command object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/right_develop/commands/server.rb', line 48

def self.create
  mode_list = MODES.sort.inject([]) do |a, (k, v)|
    a << ' * %s%s' % [k.to_s.ljust(10), v]
  end.join("\n")

  options = Trollop.options do
    banner <<-EOS
The 'server' command starts a server in the foreground (by default) to assist in testing. The behavior of the server depends on the type specified.

Usage:
  right_develop server <mode> [options]

Where <mode> is one of:
#{mode_list}

And [options] are selected from:
    EOS
    send_to_msg =
      'Configure an already-running admin service at given URL. ' +
      'The URL to PUT is specific to the admin service configuration'
    opt :root_dir, 'Root directory for config and fixtures',
        :default => ::Dir.pwd
    opt :port, 'Port on which server will listen',
        :default => 9292
    opt :force, 'Force overwrite of any existing recording',
        :default => false
    opt :throttle, 'Playback delay as a percentage of recorded response time',
        :default => 1
    opt :debug, 'Enable verbose debug output',
        :default => false
    opt :send_to, send_to_msg,
        :default => DEFAULT_SEND_TO
    opt :start, 'Start the server in the background',
        :default => false
    opt :stop, 'Stop any running server by mode, port and last known PID',
        :default => false
  end

  mode = ARGV.shift.to_s
  if MODES.keys.include?(mode)
    self.new(mode.to_sym, options)
  else
    ::Trollop.die("unknown mode #{mode}")
  end
end

Instance Method Details

#runObject

Run the mode that was specified when this object was instantiated. This method does no work; it just delegates to a mode method.



110
111
112
# File 'lib/right_develop/commands/server.rb', line 110

def run
  run_might_api(@mode, @options)
end