Sha256: 38b63ef0e2346f2b9143286ef726b326489004056290cc677f79f04560fded01

Contents?: true

Size: 1.96 KB

Versions: 2

Compression:

Stored size: 1.96 KB

Contents

module Magpie
  class Server < Rack::Server
    class Options
      def parse!(args)
        options = {}
        opt_parser = OptionParser.new("", 24, '  ') do |opts|
          opts.banner = "Usage: mag [rack options] [mag config]"

          opts.separator ""
          opts.separator "Rack options:"
          opts.on("-s", "--server SERVER", "serve using SERVER (webrick/mongrel)") { |s|
            options[:server] = s
          }

          opts.on("-o", "--host HOST", "listen on HOST (default: 0.0.0.0)") { |host|
            options[:Host] = host
          }

          opts.on("-p", "--port PORT", "use PORT (default: 9292)") { |port|
            options[:Port] = port
          }

          opts.on("-D", "--daemonize", "run daemonized in the background") { |d|
            options[:daemonize] = d ? true : false
          }

          opts.on("-P", "--pid FILE", "file to store PID (default: rack.pid)") { |f|
            options[:pid] = f
          }

          opts.separator ""
          opts.separator "Common options:"

          opts.on_tail("-h", "--help", "Show this message") do
            puts opts
            exit
          end

          opts.on_tail("--version", "Show version") do
            puts "Magpie #{Magpie.version}"
            exit
          end
        end
        opt_parser.parse! args
        options[:yml] = args.last if args.last
        options
      end
    end

    def app
      Magpie::APP
    end

    def default_options
      {
        :environment => "development",
        :pid         => nil,
        :Port        => 9292,
        :Host        => "0.0.0.0",
        :AccessLog   => [],
        :yml         => "magpie.yml"
      }
    end

    private
    def opt_parser
      Options.new
    end

    def parse_options(args)
      options = super
       if !::File.exist? options[:yml]
          abort "configuration file #{options[:yml]} not found"
        end
      Magpie.yml_db = ::YAML.load_file(options[:yml])
      options
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
magpie-0.8.6.2 lib/magpie/server.rb
magpie-0.8.6.1 lib/magpie/server.rb