Module: Roda::RodaPlugins::ClassMatchers::ClassMethods
- Defined in:
- lib/roda/plugins/class_matchers.rb
Instance Method Summary collapse
-
#class_matcher(klass, matcher, opts = OPTS, &block) ⇒ Object
Set the matcher and block to use for the given class.
-
#freeze ⇒ Object
Freeze the class_matchers hash when freezing the app.
Instance Method Details
#class_matcher(klass, matcher, opts = OPTS, &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.
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/roda/plugins/class_matchers.rb', line 106 def class_matcher(klass, matcher, opts=OPTS, &block) _symbol_class_matcher(Class, klass, matcher, block, opts) do |meth, (_, regexp, convert_meth, consume_meth)| if regexp if consume_meth == :_consume_single_segment define_method(meth){_consume_single_segment(regexp, convert_meth)} else define_method(meth){consume(regexp, convert_meth)} end else define_method(meth){_consume_segment(convert_meth)} end end end |
#freeze ⇒ Object
Freeze the class_matchers hash when freezing the app.
121 122 123 124 |
# File 'lib/roda/plugins/class_matchers.rb', line 121 def freeze opts[:class_matchers].freeze super end |