forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application_lib.rb
62 lines (40 loc) · 1013 Bytes
/
application_lib.rb
1
2
3
4
5
6
7
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
51
52
53
54
55
56
57
58
59
60
61
62
module ApplicationLib
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
=begin
load adapter based on setting option
result = self.load_adapter_by_setting('some_setting_with_class_name')
returns
result = Some::Classname
=end
def load_adapter_by_setting(setting)
adapter = Setting.get(setting)
return if adapter.blank?
# load backend
load_adapter(adapter)
end
=begin
load adapter
result = self.load_adapter('Some::Classname')
returns
result = Some::Classname
=end
def load_adapter(adapter)
# load adapter
# will only work on ruby 2.0
#Object.const_get(adapter)
# will work on ruby 1.9 and 2.0
#adapter.split('::').inject(Object) do |mod, class_name|
# mod.const_get(class_name)
#end
# will work with active_support
adapter = adapter.constantize
if !adapter
raise "Can't load adapter '#{adapter_name}'"
end
adapter
end
end
end