Sha256: f96e023573fb50caad75c99ad1f58d9a05102cfddfb8cab68d8c29534e6a3fe2

Contents?: true

Size: 1.01 KB

Versions: 19

Compression:

Stored size: 1.01 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|
    #       self['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)
          self::RodaRequest.send(:define_method, :"match_#{key}", &block)
        end
      end
    end

    register_plugin(:hash_matcher, HashMatcher)
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
roda-2.29.0 lib/roda/plugins/hash_matcher.rb
roda-2.28.0 lib/roda/plugins/hash_matcher.rb
roda-2.27.0 lib/roda/plugins/hash_matcher.rb
roda-2.26.0 lib/roda/plugins/hash_matcher.rb
roda-2.25.0 lib/roda/plugins/hash_matcher.rb
roda-2.24.0 lib/roda/plugins/hash_matcher.rb
roda-2.23.0 lib/roda/plugins/hash_matcher.rb
roda-2.22.0 lib/roda/plugins/hash_matcher.rb
roda-2.21.0 lib/roda/plugins/hash_matcher.rb
roda-2.20.0 lib/roda/plugins/hash_matcher.rb
roda-2.19.0 lib/roda/plugins/hash_matcher.rb
roda-2.18.0 lib/roda/plugins/hash_matcher.rb
roda-2.17.0 lib/roda/plugins/hash_matcher.rb
roda-2.16.0 lib/roda/plugins/hash_matcher.rb
roda-2.15.0 lib/roda/plugins/hash_matcher.rb
roda-2.14.0 lib/roda/plugins/hash_matcher.rb
roda-2.13.0 lib/roda/plugins/hash_matcher.rb
roda-2.12.0 lib/roda/plugins/hash_matcher.rb
roda-2.11.0 lib/roda/plugins/hash_matcher.rb