module Roda::RodaPlugins::ClassMatchers::ClassMethods

  1. lib/roda/plugins/class_matchers.rb

Methods

Public Instance

  1. class_matcher
  2. freeze

Public Instance methods

class_matcher(klass, matcher, opts=OPTS, &block)

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 array with the captures to yield to the match block.

[show source]
    # File lib/roda/plugins/class_matchers.rb
106 def class_matcher(klass, matcher, opts=OPTS, &block)
107   _symbol_class_matcher(Class, klass, matcher, block, opts) do |meth, (_, regexp, convert_meth, consume_meth)|
108     if regexp
109       if consume_meth == :_consume_single_segment
110         define_method(meth){_consume_single_segment(regexp, convert_meth)}
111       else
112         define_method(meth){consume(regexp, convert_meth)}
113       end
114     else
115       define_method(meth){_consume_segment(convert_meth)}
116     end
117   end
118 end
freeze()

Freeze the class_matchers hash when freezing the app.

[show source]
    # File lib/roda/plugins/class_matchers.rb
121 def freeze
122   opts[:class_matchers].freeze
123   super
124 end