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.45.0 lib/roda/plugins/pass.rb
roda-3.44.0 lib/roda/plugins/pass.rb
roda-3.43.1 lib/roda/plugins/pass.rb
roda-3.43.0 lib/roda/plugins/pass.rb
roda-3.42.0 lib/roda/plugins/pass.rb
roda-3.41.0 lib/roda/plugins/pass.rb
roda-3.40.0 lib/roda/plugins/pass.rb
roda-3.39.0 lib/roda/plugins/pass.rb
roda-3.38.0 lib/roda/plugins/pass.rb
roda-3.37.0 lib/roda/plugins/pass.rb
roda-3.36.0 lib/roda/plugins/pass.rb
roda-3.35.0 lib/roda/plugins/pass.rb
roda-3.34.0 lib/roda/plugins/pass.rb
roda-3.33.0 lib/roda/plugins/pass.rb
roda-3.32.0 lib/roda/plugins/pass.rb
roda-3.31.0 lib/roda/plugins/pass.rb
roda-3.30.0 lib/roda/plugins/pass.rb
roda-3.29.0 lib/roda/plugins/pass.rb
roda-3.28.0 lib/roda/plugins/pass.rb
roda-3.27.0 lib/roda/plugins/pass.rb