Sha256: a9907d48dc3613630e823f2bba269dea0f31b5a1a6b01ec4a41c467273c4fb0f

Contents?: true

Size: 506 Bytes

Versions: 3

Compression:

Stored size: 506 Bytes

Contents

# frozen_string_literal: true

module Jellyfish
  class Rewrite < Struct.new(:app, :from, :to)
    def call env
      app.call(env.merge(
        'SCRIPT_NAME' => delete_suffix(env['SCRIPT_NAME'], from),
        'PATH_INFO' => "#{to}#{env['PATH_INFO']}"))
    end

    if ''.respond_to?(:delete_suffix)
      def delete_suffix str, suffix
        str.delete_suffix(suffix)
      end
    else
      def delete_suffix str, suffix
        str.sub(/#{Regexp.escape(suffix)}\z/, '')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jellyfish-1.4.0 lib/jellyfish/rewrite.rb
jellyfish-1.3.1 lib/jellyfish/rewrite.rb
jellyfish-1.3.0 lib/jellyfish/rewrite.rb