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)
-
- (Object) matcher
readonly
The matcher to match against.
Class Method Summary (collapse)
-
+ (Object) inherited(condition)
Registers a condition subclass, which creates instance methods on Mailman::Route and Application.
Instance Method Summary (collapse)
-
- (Condition) initialize(condition)
constructor
A new instance of Condition.
-
- ((Hash, Array)) match(message)
abstract
A hash to merge into params, and an array of block arguments.
Constructor Details
- (Condition) initialize(condition)
A new instance of Condition
12 13 14 |
# File 'lib/mailman/route/condition.rb', line 12 def initialize(condition) @matcher = Matcher.create(condition) end |
Instance Attribute Details
- (Object) matcher (readonly)
The matcher to match against.
8 9 10 |
# File 'lib/mailman/route/condition.rb', line 8 def matcher @matcher end |
Class Method Details
+ (Object) inherited(condition)
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
- ((Hash, Array)) match(message)
This method is abstract.
Extracts the attribute from the message, and runs the matcher on it.
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 |