Sha256: bcc6bb429ca09621336ff94c5c67ebf40da02215cc3127a3e2d95eea99e646ef
Contents?: true
Size: 729 Bytes
Versions: 14
Compression:
Stored size: 729 Bytes
Contents
module Scrivito class TypeComputer def initialize(base_class, fallback_class) @base_class, @fallback_class = base_class, fallback_class end def compute_type(obj_class) load_class(obj_class) || @fallback_class end def compute_type_without_fallback(obj_class) if obj_class = load_class(obj_class) obj_class else raise ObjClassNotFound end end def special_class?(klass) klass == @base_class || klass == @fallback_class end private def load_class(obj_class) klass = obj_class.constantize klass if inherits_from_base?(klass) rescue NameError end def inherits_from_base?(klass) klass.ancestors.include?(@base_class) && klass != @base_class end end end
Version data entries
14 entries across 14 versions & 1 rubygems