Sha256: cc0a18a5933a2293b6120863112d84b2aaf9cc9ec1332e137ab89f6bacd7a1e3
Contents?: true
Size: 755 Bytes
Versions: 65
Compression:
Stored size: 755 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_name) if obj_class = load_class(obj_class_name) obj_class else raise ObjClassNotFound, obj_class_name 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
65 entries across 65 versions & 1 rubygems