Public Instance methods
Set the matcher and block to use for the given class. The matcher can be a regexp, registered class matcher, or registered symbol matcher (if using the symbol_matchers plugin).
If providing a regexp, the block given will be called with all regexp captures. If providing a registered class or symbol, the block will be called with the captures returned by the block for the registered class or symbol, or the regexp captures if no block was registered with the class or symbol. In either case, if a block is given, it should return an object to yield to the match block, or an array to yield multiple arguments to the match block. If the block returns nil or false, it will be treated as not matching.
# File lib/roda/plugins/class_matchers.rb 109 def class_matcher(klass, matcher, opts=(no_positional_opts = true; OPTS), segment: opts[:segment], **kw, &block) 110 RodaPlugins.check_keywords(__callee__, no_positional_opts, opts, kw) 111 112 _symbol_class_matcher(Class, klass, matcher, block, segment: segment) do |meth, (_, regexp, convert_meth, consume_meth)| 113 if regexp 114 if consume_meth == :_consume_single_segment 115 define_method(meth){_consume_single_segment(regexp, convert_meth)} 116 else 117 define_method(meth){consume(regexp, convert_meth)} 118 end 119 else 120 define_method(meth){_consume_segment(convert_meth)} 121 end 122 end 123 124 nil 125 end
Freeze the class_matchers hash when freezing the app.
# File lib/roda/plugins/class_matchers.rb 128 def freeze 129 class_matchers.freeze 130 super 131 end