Sha256: e3be1c730fe39e46c8cd67f620f0148c2602875ac946f1b7389b0d0127e7c7b2

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 KB

Contents

# encoding: utf-8
module LocalPac
  module ServerCommands
    class Rackup

      private

      attr_reader :environment, :pid_file, :config_file, :host, :port

      public

      def initialize(options = {})
        @environment = options.fetch(:environment, :development)
        @pid_file    = options.fetch(:pid_file, LocalPac.config.pid_file)
        @config_file = options.fetch(:config_file, ::File.expand_path('../../../../config.ru', __FILE__))
        listen       = options.fetch(:listen, '127.0.0.1:8080')

        begin
          uri = Addressable::URI.heuristic_parse(listen)
        rescue StandardError => e
          fail Exceptions::ServerListenStatementInvalid, "I cannot parse the listen statement: #{listen}. It is invalid: #{e.message}"
        end

        @port        = uri.port
        @host        = uri.host
      rescue KeyError => e
        raise ArgumentError, e.message
      end

      def to_s
        cmd = []

        cmd << 'rackup'
        cmd << "-E #{environment}" if environment
        cmd << "-P #{pid_file}" if pid_file
        cmd << "-o #{host}" if host
        cmd << "-p #{port}" if port
        cmd << config_file if config_file

        cmd.join(" ")
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
local_pac-0.10.2 lib/local_pac/server_commands/rackup.rb
local_pac-0.10.1 lib/local_pac/server_commands/rackup.rb
local_pac-0.10.0 lib/local_pac/server_commands/rackup.rb
local_pac-0.9.0 lib/local_pac/server_commands/rackup.rb
local_pac-0.7.0 lib/local_pac/server_commands/rackup.rb
local_pac-0.6.3 lib/local_pac/server_commands/rackup.rb
local_pac-0.6.2 lib/local_pac/server_commands/rackup.rb
local_pac-0.6.1 lib/local_pac/server_commands/rackup.rb
local_pac-0.5.0 lib/local_pac/server_commands/rackup.rb
local_pac-0.4.0 lib/local_pac/server_commands/rackup.rb
local_pac-0.3.0 lib/local_pac/server_commands/rackup.rb