Sha256: df92bf965490f6c44f14e34a7f3bf94f94dbda7cf6d83683a8e74b73bf43123a

Contents?: true

Size: 982 Bytes

Versions: 96

Compression:

Stored size: 982 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

96 entries across 96 versions & 1 rubygems

Version Path
roda-3.65.0 lib/roda/plugins/pass.rb
roda-3.64.0 lib/roda/plugins/pass.rb
roda-3.63.0 lib/roda/plugins/pass.rb
roda-3.62.0 lib/roda/plugins/pass.rb
roda-3.61.0 lib/roda/plugins/pass.rb
roda-3.60.0 lib/roda/plugins/pass.rb
roda-3.59.0 lib/roda/plugins/pass.rb
roda-3.58.0 lib/roda/plugins/pass.rb
roda-3.57.0 lib/roda/plugins/pass.rb
roda-3.56.0 lib/roda/plugins/pass.rb
roda-3.55.0 lib/roda/plugins/pass.rb
roda-3.54.0 lib/roda/plugins/pass.rb
roda-3.53.0 lib/roda/plugins/pass.rb
roda-3.52.0 lib/roda/plugins/pass.rb
roda-3.51.0 lib/roda/plugins/pass.rb
roda-3.50.0 lib/roda/plugins/pass.rb
roda-3.49.0 lib/roda/plugins/pass.rb
roda-3.48.0 lib/roda/plugins/pass.rb
roda-3.47.0 lib/roda/plugins/pass.rb
roda-3.46.0 lib/roda/plugins/pass.rb