Module: ScoutApm::Utils::KlassHelper
- Defined in:
- lib/scout_apm/utils/klass_helper.rb
Class Method Summary collapse
-
.defined?(*names) ⇒ Boolean
KlassHelper.defined?(“ActiveRecord”, “Base”) #=> true / false KlassHelper.defined?(“ActiveRecord::Base”) #=> true / false.
-
.lookup(*names) ⇒ Object
KlassHelper.lookup(“ActiveRecord::Base”) => ActiveRecord::Base KlassHelper.lookup(“ActiveRecord::SomethingThatDoesNotExist”) => :missing_class.
Class Method Details
.defined?(*names) ⇒ Boolean
KlassHelper.defined?(“ActiveRecord”, “Base”) #=> true / false KlassHelper.defined?(“ActiveRecord::Base”) #=> true / false
7 8 9 |
# File 'lib/scout_apm/utils/klass_helper.rb', line 7 def self.defined?(*names) lookup(*names) != :missing_class end |
.lookup(*names) ⇒ Object
KlassHelper.lookup(“ActiveRecord::Base”) => ActiveRecord::Base KlassHelper.lookup(“ActiveRecord::SomethingThatDoesNotExist”) => :missing_class
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/scout_apm/utils/klass_helper.rb', line 13 def self.lookup(*names) if names.length == 1 names = names[0].split("::") end obj = Object names.each do |name| begin obj = obj.const_get(name) rescue NameError return :missing_class end end obj end |