Class: Mailman::Route
- Inherits:
-
Object
- Object
- Mailman::Route
- Defined in:
- lib/mailman/route.rb,
lib/mailman/route/matcher.rb,
lib/mailman/route/condition.rb,
lib/mailman/route/conditions.rb,
lib/mailman/route/regexp_matcher.rb,
lib/mailman/route/string_matcher.rb
Overview
The main route class. Has condition methods defined on it by Condition.inherited. Stores a route with a set of conditions and matches against them.
Defined Under Namespace
Classes: BodyCondition, CcCondition, Condition, FromCondition, Matcher, RegexpMatcher, StringMatcher, SubjectCondition, ToCondition
Instance Attribute Summary collapse
-
#block ⇒ Proc
readonly
The block that should be run if the conditions match.
-
#conditions ⇒ Array
readonly
The list of condition instances associated with the route.
-
#klass ⇒ Class, String
readonly
The class (and optional instance method) to run instead of a block.
Instance Method Summary collapse
-
#initialize ⇒ Route
constructor
A new instance of Route.
-
#match!(message) ⇒ Hash
Checks whether a message matches the route.
Constructor Details
#initialize ⇒ Route
Returns a new instance of Route.
17 18 19 |
# File 'lib/mailman/route.rb', line 17 def initialize @conditions = [] end |
Instance Attribute Details
#block ⇒ Proc (readonly)
Returns the block that should be run if the conditions match.
8 9 10 |
# File 'lib/mailman/route.rb', line 8 def block @block end |
#conditions ⇒ Array (readonly)
Returns the list of condition instances associated with the route.
15 16 17 |
# File 'lib/mailman/route.rb', line 15 def conditions @conditions end |
#klass ⇒ Class, String (readonly)
Returns the class (and optional instance method) to run instead of a block.
12 13 14 |
# File 'lib/mailman/route.rb', line 12 def klass @klass end |
Instance Method Details
#match!(message) ⇒ Hash
Checks whether a message matches the route.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mailman/route.rb', line 25 def match!() params = {} args = [] @conditions.each do |condition| if result = condition.match() params.merge!(result[0]) args += result[1] else return nil end end { :block => @block, :klass => @klass, :params => params, :args => args } end |