Sha256: 13382a50f35f9ac7e1e241a322a8a742dfa8cbfb2fb5a4b77ba6179c5a1c2465

Contents?: true

Size: 1.08 KB

Versions: 57

Compression:

Stored size: 1.08 KB

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The hash_matcher plugin adds the hash_matcher class method, which
    # allows for easily defining hash matchers:
    #
    #   class App < Roda
    #     hash_matcher(:foo) do |v|
    #       params['foo'] == v
    #     end
    #
    #     route do
    #       r.on foo: 'bar' do
    #         # matches when param foo has value bar
    #       end
    #     end
    #   end
    module HashMatcher
      module ClassMethods
        # Create a match_#{key} method in the request class using the given
        # block, so that using a hash key in a request match method will
        # call the block.  The block should return nil or false to not
        # match, and anything else to match.  See the HashMatcher module
        # documentation for an example.
        def hash_matcher(key, &block)
          meth = :"match_#{key}"
          self::RodaRequest.send(:define_method, meth, &block)
          self::RodaRequest.send(:private, meth)
        end
      end
    end

    register_plugin(:hash_matcher, HashMatcher)
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
roda-3.88.0 lib/roda/plugins/hash_matcher.rb
roda-3.87.0 lib/roda/plugins/hash_matcher.rb
roda-3.86.0 lib/roda/plugins/hash_matcher.rb
roda-3.85.0 lib/roda/plugins/hash_matcher.rb
roda-3.84.0 lib/roda/plugins/hash_matcher.rb
roda-3.83.0 lib/roda/plugins/hash_matcher.rb
roda-3.82.0 lib/roda/plugins/hash_matcher.rb
roda-3.81.0 lib/roda/plugins/hash_matcher.rb
roda-3.79.0 lib/roda/plugins/hash_matcher.rb
roda-3.78.0 lib/roda/plugins/hash_matcher.rb
roda-3.77.0 lib/roda/plugins/hash_matcher.rb
roda-3.76.0 lib/roda/plugins/hash_matcher.rb
roda-3.75.0 lib/roda/plugins/hash_matcher.rb
roda-3.74.0 lib/roda/plugins/hash_matcher.rb
roda-3.73.0 lib/roda/plugins/hash_matcher.rb
roda-3.72.0 lib/roda/plugins/hash_matcher.rb
roda-3.71.0 lib/roda/plugins/hash_matcher.rb
roda-3.70.0 lib/roda/plugins/hash_matcher.rb
roda-3.69.0 lib/roda/plugins/hash_matcher.rb
roda-3.68.0 lib/roda/plugins/hash_matcher.rb