Sha256: 051f790564c1150b940b2c56982bcffe4c5d1015dcba3d1803269f5cb71efe3a

Contents?: true

Size: 882 Bytes

Versions: 2

Compression:

Stored size: 882 Bytes

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The slash_path_empty plugin considers "/" as an empty path,
    # in addition to the default of "" being considered an empty
    # path.  This makes it so +r.is+ without an argument will match
    # a path of "/", and +r.is+ and verb methods such as +r.get+ and
    # +r.post+ will match if the path is "/" after the arguments
    # are processed.  This can make it easier to handle applications
    # where a trailing "/" in the path should be ignored.
    module SlashPathEmpty
      SLASH = "/".freeze
      RodaPlugins.deprecate_constant(self, :SLASH)

      module RequestMethods
        private

        # Consider the path empty if it is "/".
        def empty_path?
          super || remaining_path == '/'
        end
      end
    end

    register_plugin(:slash_path_empty, SlashPathEmpty)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
roda-2.29.0 lib/roda/plugins/slash_path_empty.rb
roda-2.28.0 lib/roda/plugins/slash_path_empty.rb