Module: SMS::Backend

Defined in:
lib/rubysms/backend.rb,
lib/rubysms/backend/drb.rb,
lib/rubysms/backend/gsm.rb,
lib/rubysms/backend/http.rb,
lib/rubysms/backend/clickatell.rb

Defined Under Namespace

Classes: Base, Clickatell, DRB, GSM, HTTP

Class Method Summary collapse

Class Method Details

.create(klass, label = nil, *args) ⇒ Object

TODO: doc



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rubysms/backend.rb', line 8

def self.create(klass, label=nil, *args)

	# if a class name was passed (rather
	# than a real class), attempt to load
	# the ruby source, and resolve the name
	unless klass.is_a?(Class)
		begin
			src = File.dirname(__FILE__) +\
				"/backend/#{klass.to_s.downcase}.rb"
			require src
		
		# if the backend couldn't be required, re-
		# raise the error with a more useful message
		rescue LoadError
			raise LoadError.new(
				"Couldn't load #{klass.inspect} " +\
				"backend from: #{src}")
		end
		
		begin
			klass = SMS::Backend.const_get(klass)
		
		# if the constant couldn't be found,
		# re-raise with a more useful message
		rescue NameError
			raise LoadError.new(
				"Loaded #{klass.inspect} backend from " +\
				"#{src}, but the SMS::Backend::#{klass} "+\
				"class was not defined")
		end
	end
	
	# create an instance of this backend,
	# passing along the (optional) arguments
	inst = klass.new(*args)

	# apply the label, if one were provided.
	# if not, the backend will provide its own
	inst.label = label unless\
		label.nil?
	
	inst
end