Class: Mailman::Route::Condition
- Inherits:
-
Object
- Object
- Mailman::Route::Condition
- Defined in:
- lib/mailman/route/condition.rb
Overview
The base condition class. All conditions should subclass and override #match.
Direct Known Subclasses
BodyCondition, CcCondition, FromCondition, SubjectCondition, ToCondition
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
The matcher to match against.
Class Method Summary collapse
-
.inherited(condition) ⇒ Object
Registers a condition subclass, which creates instance methods on Mailman::Route and Application.
Instance Method Summary collapse
-
#initialize(condition) ⇒ Condition
constructor
A new instance of Condition.
-
#match(message) ⇒ (Hash, Array)
abstract
A hash to merge into params, and an array of block arguments.
Constructor Details
Instance Attribute Details
#matcher ⇒ Object (readonly)
Returns the matcher to match against.
8 9 10 |
# File 'lib/mailman/route/condition.rb', line 8 def matcher @matcher end |
Class Method Details
.inherited(condition) ⇒ Object
Registers a condition subclass, which creates instance methods on Mailman::Route and Application.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mailman/route/condition.rb', line 30 def self.inherited(condition) condition_name = condition.to_s.split('::')[-1][0...-9].downcase Route.class_eval <<-EOM def #{condition_name}(pattern, klass = nil, &block) @conditions << #{condition}.new(pattern) @klass = klass if block_given? @block = block end self end EOM Application.class_eval <<-EOM def #{condition_name}(pattern, klass = nil, &block) @router.add_route Route.new.#{condition_name}(pattern, klass, &block) end EOM end |
Instance Method Details
#match(message) ⇒ (Hash, Array)
This method is abstract.
Extracts the attribute from the message, and runs the matcher on it.
Returns a hash to merge into params, and an array of block arguments.
21 22 23 |
# File 'lib/mailman/route/condition.rb', line 21 def match() raise NotImplementedError end |