class Ferryman::Config
Attributes
providers[R]
rules[R]
Public Class Methods
new()
click to toggle source
# File lib/ferryman.rb, line 78 def initialize @providers = {} @rules = [] @arity = nil end
Public Instance Methods
add_provider(name, provider)
click to toggle source
# File lib/ferryman.rb, line 84 def add_provider(name, provider) raise ConfigError.new("Provider #{name} already exists") if @providers.has_key?(name) raise ConfigError.new("Provider must accept at least a phone number") if provider.arity < 1 raise ConfigError.new("Provider arguments does not match with existing") unless @arity.nil? || provider.arity == @arity @arity = provider.arity @providers[name] = provider true end
set_routing_table(table)
click to toggle source
# File lib/ferryman.rb, line 95 def set_routing_table(table) table.each do |row| raise ConfigError.new('providers cannot be nil!') if row[:providers].nil? rule = RoutingRule.new rule.set_match row[:match] rule.strategy = row.fetch(:strategy, 'first') row[:providers].each {|provider| rule.add_provider(provider)} @rules << rule end true end