Class: Ferryman::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ferryman.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDispatcher

Returns a new instance of Dispatcher.



113
114
115
# File 'lib/ferryman.rb', line 113

def initialize
  @config = Config.new
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



111
112
113
# File 'lib/ferryman.rb', line 111

def config
  @config
end

Instance Method Details

#deliver(phone_number, *args) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/ferryman.rb', line 117

def deliver(phone_number, *args)
  @config.rules.each do |rule|
    next unless rule.accept?(phone_number)

    rule.providers.each do |provider_name|
      provider = @config.providers[provider_name]
      params = [phone_number] + args
      begin
        return provider.call(*params)
      rescue DeliveryError
        next
      end
    end
  end

  nil
end