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.26.0 lib/roda/plugins/pass.rb
roda-3.25.0 lib/roda/plugins/pass.rb
roda-3.24.0 lib/roda/plugins/pass.rb
roda-3.23.0 lib/roda/plugins/pass.rb
roda-3.22.0 lib/roda/plugins/pass.rb
roda-3.21.0 lib/roda/plugins/pass.rb
roda-3.20.0 lib/roda/plugins/pass.rb
roda-3.19.0 lib/roda/plugins/pass.rb
roda-3.18.0 lib/roda/plugins/pass.rb
roda-3.17.0 lib/roda/plugins/pass.rb
roda-3.16.0 lib/roda/plugins/pass.rb
roda-3.15.0 lib/roda/plugins/pass.rb
roda-3.14.1 lib/roda/plugins/pass.rb
roda-3.14.0 lib/roda/plugins/pass.rb
roda-3.13.0 lib/roda/plugins/pass.rb
roda-3.12.0 lib/roda/plugins/pass.rb
roda-3.11.0 lib/roda/plugins/pass.rb
roda-3.10.0 lib/roda/plugins/pass.rb
roda-3.9.0 lib/roda/plugins/pass.rb
roda-3.8.0 lib/roda/plugins/pass.rb