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.86.0 lib/roda/plugins/pass.rb
roda-3.85.0 lib/roda/plugins/pass.rb
roda-3.84.0 lib/roda/plugins/pass.rb
roda-3.83.0 lib/roda/plugins/pass.rb
roda-3.82.0 lib/roda/plugins/pass.rb
roda-3.81.0 lib/roda/plugins/pass.rb
roda-3.79.0 lib/roda/plugins/pass.rb
roda-3.78.0 lib/roda/plugins/pass.rb
roda-3.77.0 lib/roda/plugins/pass.rb
roda-3.76.0 lib/roda/plugins/pass.rb
roda-3.75.0 lib/roda/plugins/pass.rb
roda-3.74.0 lib/roda/plugins/pass.rb
roda-3.73.0 lib/roda/plugins/pass.rb
roda-3.72.0 lib/roda/plugins/pass.rb
roda-3.71.0 lib/roda/plugins/pass.rb
roda-3.70.0 lib/roda/plugins/pass.rb
roda-3.69.0 lib/roda/plugins/pass.rb
roda-3.68.0 lib/roda/plugins/pass.rb
roda-3.67.0 lib/roda/plugins/pass.rb
roda-3.66.0 lib/roda/plugins/pass.rb