Class: ArSerializer::GraphQL::TypeClass

Inherits:
Object
  • Object
show all
Includes:
Serializable
Defined in:
lib/ar_serializer/graphql/types.rb

Defined Under Namespace

Classes: InvalidType

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ TypeClass

Returns a new instance of TypeClass.



100
101
102
# File 'lib/ar_serializer/graphql/types.rb', line 100

def initialize(type)
  @type = type
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



99
100
101
# File 'lib/ar_serializer/graphql/types.rb', line 99

def type
  @type
end

Class Method Details

.from(type, only = nil, except = nil) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/ar_serializer/graphql/types.rb', line 127

def self.from(type, only = nil, except = nil)
  type = [type[0...-1].to_sym, nil] if type.is_a?(Symbol) && type.to_s.end_with?('?')
  type = [type[0...-1], nil] if type.is_a?(String) && type.end_with?('?') # ??
  case type
  when Class
    raise InvalidType, "#{type} must include ArSerializer::Serializable" unless type.ancestors.include? ArSerializer::Serializable

    SerializableTypeClass.new type, only, except
  when :number, :int, :float, :string, :boolean, :any, :unknown
    ScalarTypeClass.new type
  when String, Numeric, true, false, nil
    ScalarTypeClass.new type
  when Array
    if type.size == 1
      ListTypeClass.new from(type.first, only, except)
    elsif type.size == 2 && type.last.nil?
      OptionalTypeClass.new from(type.first, only, except)
    else
      OrTypeClass.new type.map {|v| from(v, only, except) }
    end
  when Hash
    HashTypeClass.new type.transform_values {|v| from(v, only, except) }
  when ArSerializer::TSType
    TSTypeClass.new type.type
  else
    raise InvalidType, "Invalid type: #{type}"
  end
end

Instance Method Details

#association_typeObject



118
# File 'lib/ar_serializer/graphql/types.rb', line 118

def association_type; end

#collect_types(types) ⇒ Object



106
# File 'lib/ar_serializer/graphql/types.rb', line 106

def collect_types(types); end

#descriptionObject



108
# File 'lib/ar_serializer/graphql/types.rb', line 108

def description = ts_type

#fieldsObject



114
# File 'lib/ar_serializer/graphql/types.rb', line 114

def fields; end

#nameObject



110
# File 'lib/ar_serializer/graphql/types.rb', line 110

def name; end

#of_typeObject



112
# File 'lib/ar_serializer/graphql/types.rb', line 112

def of_type; end

#ts_typeObject



116
# File 'lib/ar_serializer/graphql/types.rb', line 116

def ts_type; end