Class: Rounders::Handlers::Handler

Inherits:
Object
  • Object
show all
Includes:
Plugins::Pluggable
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.



43
44
45
46
# File 'lib/rounders/handlers/handler.rb', line 43

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

Instance Attribute Details

#matchesObject (readonly)

Returns the value of attribute matches.



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

def matches
  @matches
end

#rounderObject (readonly)

Returns the value of attribute rounder.



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

def rounder
  @rounder
end

Class Method Details

.dispatch(rounder, mails) ⇒ Object



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

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(child_class) ⇒ Object



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

def inherited(child_class)
  Rounders.handlers << child_class
end

.on(option, method_name) ⇒ Object



31
32
33
34
# File 'lib/rounders/handlers/handler.rb', line 31

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