Class: LazyGraph::CLI
- Inherits:
-
Object
- Object
- LazyGraph::CLI
- Defined in:
- lib/lazy_graph/cli.rb
Class Method Summary collapse
-
.invoke!(rack_app) ⇒ Object
A builder group rack-app can be exposed via a simple rack based HTTP server with routes corresponding to each builder class deeply nested withhin the builder group module.
Class Method Details
.invoke!(rack_app) ⇒ Object
A builder group rack-app can be exposed via a simple rack based HTTP server with routes corresponding to each builder class deeply nested withhin the builder group module.
8 9 10 11 12 13 14 15 16 17 18 19 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 |
# File 'lib/lazy_graph/cli.rb', line 8 def self.invoke!(rack_app) require 'etc' require 'optparse' require 'rack' = { port: 9292, workers: (Environment.development? ? 1 : Etc.nprocessors) } OptionParser.new do |opts| opts. = "Usage: #{$0} [options]" opts.on('-p PORT', '--port PORT', Integer, "Set the port (default: #{[:port]})") do |p| [:port] = p end opts.on('-w WORKERS', '--workers WORKERS', Integer, "Set the number of workers (default: #{[:workers]})") do |w| [:workers] = w end opts.on('-h', '--help', 'Print this help') do puts opts exit end end.parse! # A builder group can be exposed as a simple rack based HTTP server # with routes corresponding to each builder class deeply nested # withhin the builder group module. RackServer.new( Rack::Builder.new do use Rack::Lint if Environment.development? run rack_app end ).start(port: [:port], workers: [:workers]) end |