Class: Mailman::Route::Condition

Inherits:
Object
  • Object
show all
Defined in:
lib/mailman/route/condition.rb

Overview

The base condition class. All conditions should subclass and override #match.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(condition) ⇒ Condition

Returns a new instance of Condition.

Parameters:

  • the (String, Regexp)

    raw matcher to use in the condition, converted to a matcher instance by Matcher.create


12
13
14
# File 'lib/mailman/route/condition.rb', line 12

def initialize(condition)
  @matcher = Matcher.create(condition)
end

Instance Attribute Details

#matcherObject (readonly)

Returns the matcher to match against.

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.

Parameters:

  • condition (Class)

    the condition subclass to register. The method name is extracted by taking the class name, such as ToCondition, and removing the Condition ending


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.

Parameters:

  • message (Mail::Message)

    The message to match against

Returns:

  • ((Hash, Array))

    a hash to merge into params, and an array of block arguments.

Raises:

  • (NotImplementedError)

21
22
23
# File 'lib/mailman/route/condition.rb', line 21

def match(message)
  raise NotImplementedError
end