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
#initialize(condition) ⇒ Condition
Returns 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
#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 " def \#{condition_name}(pattern, klass = nil, &block)\n @conditions << \#{condition}.new(pattern)\n @klass = klass\n if block_given?\n @block = block\n end\n self\n end\n EOM\n\n Application.class_eval <<-EOM\n def \#{condition_name}(pattern, klass = nil, &block)\n @router.add_route Route.new.\#{condition_name}(pattern, klass, &block)\n end\n EOM\nend\n" |
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 |