trabajo-afectivo/lib/application_lib.rb

51 lines
793 B
Ruby
Raw Normal View History

class ApplicationLib
2013-08-15 21:15:05 +00:00
=begin
load adapter based on setting option
2013-08-15 22:11:10 +00:00
result = self.load_adapter_by_setting( 'some_setting_with_class_name' )
2013-08-15 21:15:05 +00:00
returns
2013-08-17 16:09:06 +00:00
result = Some::Classname
2013-08-15 21:15:05 +00:00
=end
def self.load_adapter_by_setting(setting)
adapter = Setting.get( setting )
return if !adapter
# load backend
self.load_adapter(adapter)
end
2013-08-15 21:15:05 +00:00
=begin
load adapter
2013-08-17 16:09:06 +00:00
result = self.load_adapter( 'Some::Classname' )
2013-08-15 21:15:05 +00:00
returns
2013-08-17 16:09:06 +00:00
result = Some::Classname
2013-08-15 21:15:05 +00:00
=end
def self.load_adapter(adapter)
# load adapter
2013-08-17 16:09:06 +00:00
# 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.constantize
end
end