Sha256: 4d95e2e3de9b26831d438d789e1501771f993df61b5ec506ce11c21726d1c9e8

Contents?: true

Size: 864 Bytes

Versions: 24

Compression:

Stored size: 864 Bytes

Contents

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|
    #       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(_)
          catch(:pass){super}
        end
      end
    end

    register_plugin(:pass, Pass)
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
roda-1.0.0 lib/roda/plugins/pass.rb
roda-cj-0.9.6 lib/roda/plugins/pass.rb
roda-cj-0.9.5 lib/roda/plugins/pass.rb
roda-cj-0.9.4 lib/roda/plugins/pass.rb