class ArSerializer::GraphQL::TypeClass
Attributes
except[R]
only[R]
type[R]
Public Class Methods
from(type, only = nil, except = nil)
click to toggle source
# File lib/ar_serializer/graphql/types.rb, line 155 def self.from(type, only = nil, except = nil) type = [type[0...-1].to_sym, nil] if type.is_a?(Symbol) && type.to_s.ends_with?('?') type = [type[0...-1], nil] if type.is_a?(String) && type.ends_with?('?') case type when Class SerializableTypeClass.new type, only, except when Symbol, String, Numeric, true, false, nil ScalarTypeClass.new type when Array if type.size == 1 ListTypeClass.new type.first, only, except elsif type.size == 2 && type.last.nil? OptionalTypeClass.new type else OrTypeClass.new type, only, except end when Hash HashTypeClass.new type, only, except end end
new(type, only = nil, except = nil)
click to toggle source
# File lib/ar_serializer/graphql/types.rb, line 96 def initialize(type, only = nil, except = nil) @type = type @only = only @except = except validate! end
Public Instance Methods
association_type()
click to toggle source
# File lib/ar_serializer/graphql/types.rb, line 146 def association_type; end
collect_types(types)
click to toggle source
# File lib/ar_serializer/graphql/types.rb, line 130 def collect_types(types); end
description()
click to toggle source
# File lib/ar_serializer/graphql/types.rb, line 132 def description ts_type end
fields()
click to toggle source
# File lib/ar_serializer/graphql/types.rb, line 140 def fields; end
name()
click to toggle source
# File lib/ar_serializer/graphql/types.rb, line 136 def name; end
of_type()
click to toggle source
# File lib/ar_serializer/graphql/types.rb, line 138 def of_type; end
sample()
click to toggle source
# File lib/ar_serializer/graphql/types.rb, line 142 def sample; end
ts_type()
click to toggle source
# File lib/ar_serializer/graphql/types.rb, line 144 def ts_type; end
validate!()
click to toggle source
# File lib/ar_serializer/graphql/types.rb, line 105 def validate! valid_symbols = %i[number int float string boolean any] invalids = [] recursive_validate = lambda do |t| case t when Array t.each { |v| recursive_validate.call v } when Hash t.each_value { |v| recursive_validate.call v } when String, Numeric, true, false, nil return when Class invalids << t unless t.ancestors.include? ArSerializer::Serializable when Symbol invalids << t unless valid_symbols.include? t.to_s.gsub(/\?$/, '').to_sym else invalids << t end end recursive_validate.call type return if invalids.empty? message = "Valid types are String, Numeric, Hash, Array, ArSerializer::Serializable, true, false, nil and Symbol#{valid_symbols}" raise InvalidType, "Invalid type: #{invalids.map(&:inspect).join(', ')}. #{message}" end