Class: Mailman::Route::Matcher
- Inherits:
-
Object
- Object
- Mailman::Route::Matcher
- Defined in:
- lib/mailman/route/matcher.rb
Overview
The base matcher class. All matchers should subclass and override #match and Matcher.valid_pattern?. Override #compile! if a pattern compiler is needed.
Direct Known Subclasses
Class Attribute Summary collapse
-
.matchers ⇒ <Class>
readonly
The array of registered matchers.
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
The matcher pattern, normally stored as a
Regexp
.
Class Method Summary collapse
-
.create(pattern) ⇒ Object
Finds and creates a valid matcher instance for a given pattern.
-
.inherited(matcher) ⇒ Object
Registers a matcher so that it can be used in Matcher.create.
- .valid_pattern?(pattern) ⇒ true, false abstract
Instance Method Summary collapse
- #compile! ⇒ Object abstract
-
#initialize(pattern) ⇒ Matcher
constructor
Creates a new matcher and calls #compile!.
-
#match(string) ⇒ (Hash, Array)
abstract
A hash to merge into params, and an array of arguments for the block.
Constructor Details
Class Attribute Details
.matchers ⇒ <Class> (readonly)
Returns The array of registered matchers.
34 35 36 |
# File 'lib/mailman/route/matcher.rb', line 34 def matchers @matchers end |
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the matcher pattern, normally stored as a Regexp
.
9 10 11 |
# File 'lib/mailman/route/matcher.rb', line 9 def pattern @pattern end |
Class Method Details
.create(pattern) ⇒ Object
Finds and creates a valid matcher instance for a given pattern.
45 46 47 48 49 |
# File 'lib/mailman/route/matcher.rb', line 45 def create(pattern) @matchers.each do |matcher| return matcher.new(pattern) if matcher.valid_pattern?(pattern) end end |
.inherited(matcher) ⇒ Object
Registers a matcher so that it can be used in create.
38 39 40 41 |
# File 'lib/mailman/route/matcher.rb', line 38 def inherited(matcher) @matchers ||= [] @matchers << matcher end |
.valid_pattern?(pattern) ⇒ true, false
Checks whether a pattern is valid.
54 55 56 |
# File 'lib/mailman/route/matcher.rb', line 54 def valid_pattern?(pattern) raise NotImplementedError end |
Instance Method Details
#compile! ⇒ Object
Compiles the pattern into something easier to work with, usually a Regexp
.
28 29 |
# File 'lib/mailman/route/matcher.rb', line 28 def compile! end |
#match(string) ⇒ (Hash, Array)
Matches a string against the stored pattern.
Returns a hash to merge into params, and an array of arguments for the block.
22 23 24 |
# File 'lib/mailman/route/matcher.rb', line 22 def match(string) raise NotImplementedError end |