Sha256: 4be795e5c10ae72b70ef5a8891548aa18014ca5058f8cf2206ac8d49e6bc0f6d

Contents?: true

Size: 1020 Bytes

Versions: 16

Compression:

Stored size: 1020 Bytes

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The match_hook plugin adds hooks that are called upon a successful match
    # by any of the matchers.  The hooks do not take any arguments.  If you would
    # like hooks that pass the arguments/matchers and values yielded to the route block,
    # use the match_hook_args plugin. This uses the match_hook_args plugin internally,
    # but doesn't pass the matchers and values yielded.
    #
    #   plugin :match_hook
    #
    #   match_hook do
    #     logger.debug("#{request.matched_path} matched. #{request.remaining_path} remaining.")
    #   end
    module MatchHook
      def self.load_dependencies(app)
        app.plugin :match_hook_args
      end

      module ClassMethods
        # Add a match hook.
        def match_hook(&block)
          meth = define_roda_method("match_hook", 0, &block)
          add_match_hook{|_,_| send(meth)}
          nil
        end
      end
    end

    register_plugin :match_hook, MatchHook
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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