Class: Mailman::Route

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeRoute

Returns a new instance of Route.



17
18
19
# File 'lib/mailman/route.rb', line 17

def initialize
  @conditions = []
end

Instance Attribute Details

#blockProc (readonly)

Returns the block that should be run if the conditions match.

Returns:

  • (Proc)

    the block that should be run if the conditions match



8
9
10
# File 'lib/mailman/route.rb', line 8

def block
  @block
end

#conditionsArray (readonly)

Returns the list of condition instances associated with the route.

Returns:

  • (Array)

    the list of condition instances associated with the route



15
16
17
# File 'lib/mailman/route.rb', line 15

def conditions
  @conditions
end

#klassClass, String (readonly)

Returns the class (and optional instance method) to run instead of a block.

Returns:

  • (Class, String)

    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.

Parameters:

  • message (Mail::Message)

    the message to match against

Returns:

  • (Hash)

    the :block and :klass associated with the route, the :params hash, and the block :args array.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mailman/route.rb', line 25

def match!(message)
  params = {}
  args = []
  @conditions.each do |condition|
    if result = condition.match(message)
      params.merge!(result[0])
      args += result[1]
    else
      return nil
    end
  end
  { :block => @block, :klass => @klass, :params => params, :args => args }
end