Class: AnySMS::Configuration

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

Overview

Configuration object for AnySMS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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

#backendsObject (readonly)

returns list of registered sms backends



24
25
26
# File 'lib/any_sms/configuration.rb', line 24

def backends
  @backends
end

#default_backendObject

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

Parameters:

  • key (Symbol)

    Key for acessing backend in any part of AnySMS

  • classname (Class)

    Real class implementation of sms backend

  • params (Hash) (defaults to: {})

    Optional params for backend. Useful for passing tokens and options

Raises:

  • (ArgumentError)


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

Parameters:

  • key (Symbol)

    Key of already registered 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