Class: Ferryman::Config
- Inherits:
-
Object
- Object
- Ferryman::Config
- Defined in:
- lib/ferryman.rb
Instance Attribute Summary collapse
-
#providers ⇒ Object
readonly
Returns the value of attribute providers.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #add_provider(name, provider) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #set_routing_table(table) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
78 79 80 81 82 |
# File 'lib/ferryman.rb', line 78 def initialize @providers = {} @rules = [] @arity = nil end |
Instance Attribute Details
#providers ⇒ Object (readonly)
Returns the value of attribute providers.
76 77 78 |
# File 'lib/ferryman.rb', line 76 def providers @providers end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
76 77 78 |
# File 'lib/ferryman.rb', line 76 def rules @rules end |
Instance Method Details
#add_provider(name, provider) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# 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) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# 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 |