application_lib.rb 793 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. class ApplicationLib
  2. =begin
  3. load adapter based on setting option
  4. result = self.load_adapter_by_setting( 'some_setting_with_class_name' )
  5. returns
  6. result = Some::Classname
  7. =end
  8. def self.load_adapter_by_setting(setting)
  9. adapter = Setting.get( setting )
  10. return if !adapter
  11. # load backend
  12. self.load_adapter(adapter)
  13. end
  14. =begin
  15. load adapter
  16. result = self.load_adapter( 'Some::Classname' )
  17. returns
  18. result = Some::Classname
  19. =end
  20. def self.load_adapter(adapter)
  21. # load adapter
  22. # will only work on ruby 2.0
  23. # Object.const_get(adapter)
  24. # will work on ruby 1.9 and 2.0
  25. # adapter.split('::').inject(Object) do |mod, class_name|
  26. # mod.const_get(class_name)
  27. # end
  28. # will work with active_support
  29. adapter.constantize
  30. end
  31. end