Sha256: 56b81564d9e81a7678ab934020759a80df3ee20f4894e686996721ce8f6d0454

Contents?: true

Size: 981 Bytes

Versions: 10

Compression:

Stored size: 981 Bytes

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The pass plugin adds a request +pass+ method to skip the current match
    # block as if it did not match.
    #
    #   plugin :pass
    #
    #   route do |r|
    #     r.on "foo/:bar" do |bar|
    #       r.pass if bar == 'baz'
    #       "/foo/#{bar} (not baz)"
    #     end
    #
    #     r.on "foo/baz" do
    #       "/foo/baz"
    #     end
    #   end
    module Pass
      module RequestMethods
        # Skip the current match block as if it did not match.
        def pass
          throw :pass
        end

        private

        # Handle passing inside the match block.
        def always
          catch(:pass){super}
        end

        # Handle passing inside the match block.
        def if_match(_)
          rp = @remaining_path
          ret = catch(:pass){super}
          @remaining_path = rp
          ret
        end
      end
    end

    register_plugin(:pass, Pass)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
roda-2.21.0 lib/roda/plugins/pass.rb
roda-2.20.0 lib/roda/plugins/pass.rb
roda-2.19.0 lib/roda/plugins/pass.rb
roda-2.18.0 lib/roda/plugins/pass.rb
roda-2.17.0 lib/roda/plugins/pass.rb
roda-2.16.0 lib/roda/plugins/pass.rb
roda-2.15.0 lib/roda/plugins/pass.rb
roda-2.14.0 lib/roda/plugins/pass.rb
roda-2.13.0 lib/roda/plugins/pass.rb
roda-2.12.0 lib/roda/plugins/pass.rb