Module: Roda::RodaPlugins::ClassMatchers::ClassMethods

Defined in:
lib/roda/plugins/class_matchers.rb

Instance Method Summary collapse

Instance Method Details

#class_matcher(klass, matcher, &block) ⇒ Object

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.



95
96
97
98
99
100
101
102
103
# File 'lib/roda/plugins/class_matchers.rb', line 95

def class_matcher(klass, matcher, &block)
  _symbol_class_matcher(Class, klass, matcher, block) do |meth, (_, regexp, convert_meth)|
    if regexp
      define_method(meth){consume(regexp, convert_meth)}
    else
      define_method(meth){_consume_segment(convert_meth)}
    end
  end
end

#freezeObject

Freeze the class_matchers hash when freezing the app.



106
107
108
109
# File 'lib/roda/plugins/class_matchers.rb', line 106

def freeze
  opts[:class_matchers].freeze
  super
end