Sha256: 6d6461fb0ae0aefec4f4b655b140eeb67e94f738f064d19649d24d8795ad7a8c

Contents?: true

Size: 909 Bytes

Versions: 3

Compression:

Stored size: 909 Bytes

Contents

# frozen_string_literal: true

module BreezyPDFLite::Intercept
  # :nodoc
  class Base
    attr_reader :app, :env

    def initialize(app, env)
      @app = app
      @env = env
    end

    private

    def rendered_url
      "#{base_url}#{path}#{query_string}"
    end

    def requested_url
      "#{env['rack.url_scheme']}://#{env['SERVER_NAME']}#{port}" \
      "#{env['PATH_INFO']}#{query_string}"
    end

    def base_url
      "#{env['rack.url_scheme']}://#{env['SERVER_NAME']}#{port}"
    end

    def port
      ":#{env['SERVER_PORT']}" unless [80, 443].include?(env["SERVER_PORT"].to_i)
    end

    def path
      BreezyPDFLite.middleware_path_matchers.reduce(env["PATH_INFO"]) do |path, matcher|
        path.gsub(matcher, "")
      end
    end

    def query_string
      return "" if env["QUERY_STRING"].nil?

      env["QUERY_STRING"] == "" ? "" : "?#{env['QUERY_STRING']}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
breezy_pdf_lite-0.0.3 lib/breezy_pdf_lite/intercept/base.rb
breezy_pdf_lite-0.0.2 lib/breezy_pdf_lite/intercept/base.rb
breezy_pdf_lite-0.0.1 lib/breezy_pdf_lite/intercept/base.rb