Sha256: 83975aef184857b978b5934562d199aee4ade09d82a6cee8ecf71cfaad0fcb84

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'heroku/forward/backends/base'

module Heroku
  module Forward
    module Backends
      class Puma < Base
        attr_accessor :config_file

        def initialize(options = {})
          @application = options[:application]
          @socket = options[:socket] || Heroku::Forward::Utils::Dir.tmp_filename('puma-', '.sock')
          @env = options[:env] || 'development'
          @config_file = options[:config_file]
        end

        def spawn!
          return false if spawned?
          check!

          args = ['puma']
          args.push '--environment', @env
          args.push '--config', @config_file if @config_file
          args.push '--bind', "unix://#{@socket}"
          args.push @application

          @pid = Spoon.spawnp(*args)
          @spawned = true
        end

        def terminate!
          return false unless spawned?
          Process.kill 'QUIT', @pid
          @spawned = false
          true
        end

        def spawned?
          !!@spawned
        end

        private

        def check!
          raise Heroku::Forward::Errors::MissingBackendOptionError.new('application') unless @application && @application.length > 0
          raise Heroku::Forward::Errors::MissingBackendApplicationError.new(@application) unless File.exists?(@application)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
heroku-forward-0.4.0 lib/heroku/forward/backends/puma.rb