Sha256: b12997728811d13590f214080c3ffeaa172693785da6ae96f2b53b50de1b6e2a
Contents?: true
Size: 852 Bytes
Versions: 44
Compression:
Stored size: 852 Bytes
Contents
module JsonApiClient module Utils def self.compute_type(klass, type_name) # If the type is prefixed with a scope operator then we assume that # the type_name is an absolute reference. return type_name.constantize if type_name.match(/^::/) # Build a list of candidates to search for candidates = [] klass.name.scan(/::|$/) { candidates.unshift "#{$`}::#{type_name}" } candidates << type_name candidates.each do |candidate| begin constant = candidate.constantize return constant if candidate == constant.to_s rescue NameError => e # We don't want to swallow NoMethodError < NameError errors raise e unless e.instance_of?(NameError) end end raise NameError, "uninitialized constant #{candidates.first}" end end end
Version data entries
44 entries across 44 versions & 1 rubygems