module Wallaby::Classifier
Concern to handle the conversion between Class and String
Public Instance Methods
to_class(name)
click to toggle source
Convert String to Class. If not String, unchanged. @param name [Object] @return [Class] if name is a Class @return [Object] if name is not a String @return [nil] if class cannot be found
# File lib/wallaby/classifier.rb, line 19 def to_class(name) return name unless name.is_a? String # NOTE: DO NOT try to use const_defined? and const_get EVER. # This is Rails, use constantize name.constantize rescue NameError Logger.error "`#{name}` is not a valid Class name." end
to_class_name(klass)
click to toggle source
Convert Class to String. If not Class, unchanged. @param klass [Object] @return [String] if klass is a Class @return [Object] if klass is not a Class
# File lib/wallaby/classifier.rb, line 10 def to_class_name(klass) klass.try(:name) || klass || nil end