Sha256: 008a3090019a79645bdac5f10eab756218c06dc0c30f567d329acd07446914f6

Contents?: true

Size: 1.31 KB

Versions: 20

Compression:

Stored size: 1.31 KB

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The empty_root plugin makes +r.root+ match both on +/+ and
    # on the empty string.  This is mostly useful when using multiple
    # rack applications, where the initial PATH_INFO has been moved
    # to SCRIPT_NAME.  For example, if you have the following
    # applications:
    #
    #   class App1 < Roda
    #     on "albums" do
    #       run App2
    #     end
    #   end
    #
    #   class App2 < Roda
    #     plugin :empty_root
    #
    #     route do |r|
    #       r.root do
    #         "root"
    #       end
    #     end
    #   end
    #
    # Then requests for both +/albums/+ and +/albums+ will return
    # "root".  Without this plugin loaded into App2, only requests
    # for +/albums/+ will return "root", since by default, +r.root+
    # matches only when the current PATH_INFO is +/+ and not when
    # it is empty.
    module EmptyRoot
      module RequestMethods
        # Match when the remaining path is the empty string,
        # in addition to the default behavior of matching when
        # the remaining path is +/+.
        def root(&block)
          super
          if remaining_path == '' && is_get?
            always(&block)
          end
        end
      end
    end

    register_plugin(:empty_root, EmptyRoot)
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
roda-3.18.0 lib/roda/plugins/empty_root.rb
roda-3.17.0 lib/roda/plugins/empty_root.rb
roda-3.16.0 lib/roda/plugins/empty_root.rb
roda-3.15.0 lib/roda/plugins/empty_root.rb
roda-3.14.1 lib/roda/plugins/empty_root.rb
roda-3.14.0 lib/roda/plugins/empty_root.rb
roda-3.13.0 lib/roda/plugins/empty_root.rb
roda-3.12.0 lib/roda/plugins/empty_root.rb
roda-3.11.0 lib/roda/plugins/empty_root.rb
roda-3.10.0 lib/roda/plugins/empty_root.rb
roda-3.9.0 lib/roda/plugins/empty_root.rb
roda-3.8.0 lib/roda/plugins/empty_root.rb
roda-3.7.0 lib/roda/plugins/empty_root.rb
roda-3.6.0 lib/roda/plugins/empty_root.rb
roda-3.5.0 lib/roda/plugins/empty_root.rb
roda-3.4.0 lib/roda/plugins/empty_root.rb
roda-3.3.0 lib/roda/plugins/empty_root.rb
roda-3.2.0 lib/roda/plugins/empty_root.rb
roda-3.1.0 lib/roda/plugins/empty_root.rb
roda-3.0.0 lib/roda/plugins/empty_root.rb