Class: Rounders::Handlers::Handler

Inherits:
Object
  • Object
show all
Includes:
Plugins::Pluggable, Topping::Configurable::Branch
Defined in:
lib/rounders/handlers/handler.rb

Defined Under Namespace

Classes: Dispatcher

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugins::Pluggable

included

Constructor Details

#initialize(rounder, matches) ⇒ Handler

Returns a new instance of Handler.



45
46
47
48
# File 'lib/rounders/handlers/handler.rb', line 45

def initialize(rounder, matches)
  @rounder = rounder
  @matches = matches
end

Instance Attribute Details

#matchesObject (readonly)

Returns the value of attribute matches.



6
7
8
# File 'lib/rounders/handlers/handler.rb', line 6

def matches
  @matches
end

#rounderObject (readonly)

Returns the value of attribute rounder.



6
7
8
# File 'lib/rounders/handlers/handler.rb', line 6

def rounder
  @rounder
end

Class Method Details

.dispatch(rounder, mails) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/rounders/handlers/handler.rb', line 23

def dispatch(rounder, mails)
  mails.map do |mail|
    dispatchers.each do |dispatcher|
      matches = dispatcher.matcher.match(mail)
      next if matches.nil?
      new(rounder, matches).public_send(dispatcher.method_name, mail)
    end
  end
end

.inherited(klass) ⇒ Object



18
19
20
21
# File 'lib/rounders/handlers/handler.rb', line 18

def inherited(klass)
  super
  Rounders.handlers << klass
end

.on(option, method_name) ⇒ Object



33
34
35
36
# File 'lib/rounders/handlers/handler.rb', line 33

def on(option, method_name)
  matcher = Rounders::Matchers::Matcher.build(option)
  dispatchers << Dispatcher.new(method_name, matcher)
end