Class: AnySMS::Configuration
- Inherits:
-
Object
- Object
- AnySMS::Configuration
- Defined in:
- lib/any_sms/configuration.rb
Overview
Configuration object for AnySMS
Instance Attribute Summary collapse
-
#backends ⇒ Object
readonly
returns list of registered sms backends.
-
#default_backend ⇒ Object
returns key of the default sms backend.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#register_backend(key, classname, params = {}) ⇒ Object
Register sms provider backend.
-
#remove_backend(key) ⇒ Object
Removes registered sms backend.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
26 27 28 29 |
# File 'lib/any_sms/configuration.rb', line 26 def initialize register_backend :null_sender, AnySMS::Backend::NullSender self.default_backend = :null_sender end |
Instance Attribute Details
#backends ⇒ Object (readonly)
returns list of registered sms backends
24 25 26 |
# File 'lib/any_sms/configuration.rb', line 24 def backends @backends end |
#default_backend ⇒ Object
returns key of the default sms backend
21 22 23 |
# File 'lib/any_sms/configuration.rb', line 21 def default_backend @default_backend end |
Instance Method Details
#register_backend(key, classname, params = {}) ⇒ Object
Register sms provider backend
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/any_sms/configuration.rb', line 50 def register_backend(key, classname, params = {}) raise ArgumentError, "backend key must be a symbol!" unless key.is_a? Symbol unless classname.class == Class raise ArgumentError, "backend class must be class (not instance or string)" end unless classname.method_defined? :send_sms raise ArgumentError, "backend must provide method send_sms" end define_backend(key, classname, params) end |
#remove_backend(key) ⇒ Object
Removes registered sms backend
67 68 69 70 71 72 73 74 |
# File 'lib/any_sms/configuration.rb', line 67 def remove_backend(key) if key == default_backend raise ArgumentError, "Removing default_backend is prohibited" end @backends.delete key true end |