Class: ArSerializer::GraphQL::SerializableTypeClass

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

Instance Attribute Summary

Attributes inherited from TypeClass

#except, #only, #type

Instance Method Summary collapse

Methods inherited from TypeClass

#description, from, #initialize, #of_type, #sample, #validate!

Constructor Details

This class inherits a constructor from ArSerializer::GraphQL::TypeClass

Instance Method Details

#==(t) ⇒ Object



341
342
343
# File 'lib/ar_serializer/graphql/types.rb', line 341

def == t
  eql? t
end

#association_typeObject



325
326
327
# File 'lib/ar_serializer/graphql/types.rb', line 325

def association_type
  self
end

#collect_types(types) ⇒ Object



319
320
321
322
323
# File 'lib/ar_serializer/graphql/types.rb', line 319

def collect_types(types)
  return if types[self]
  types[self] = true
  fields.each { |field| field.collect_types types }
end

#compare_elementsObject



345
346
347
# File 'lib/ar_serializer/graphql/types.rb', line 345

def compare_elements
  [type, field_only, field_except]
end

#eql?(t) ⇒ Boolean

Returns:

  • (Boolean)


337
338
339
# File 'lib/ar_serializer/graphql/types.rb', line 337

def eql?(t)
  self.class == t.class && self.compare_elements == t.compare_elements
end

#field_exceptObject



290
291
292
# File 'lib/ar_serializer/graphql/types.rb', line 290

def field_except
  [*except].map(&:to_s)
end

#field_onlyObject



286
287
288
# File 'lib/ar_serializer/graphql/types.rb', line 286

def field_only
  [*only].map(&:to_s)
end

#fieldsObject



311
312
313
314
315
316
317
# File 'lib/ar_serializer/graphql/types.rb', line 311

def fields
  keys = type._serializer_field_keys - ['__schema'] - field_except
  keys = field_only & keys unless field_only.empty?
  keys.map do |name|
    FieldClass.new name, type._serializer_field_info(name)
  end
end

#gql_typeObject



329
330
331
# File 'lib/ar_serializer/graphql/types.rb', line 329

def gql_type
  name
end

#hashObject



349
350
351
# File 'lib/ar_serializer/graphql/types.rb', line 349

def hash
  compare_elements.hash
end

#kindObject



294
295
296
# File 'lib/ar_serializer/graphql/types.rb', line 294

def kind
  'OBJECT'
end

#nameObject



298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/ar_serializer/graphql/types.rb', line 298

def name
  name_segments = [type.name.delete(':')]
  unless field_only.empty?
    name_segments << 'Only'
    name_segments << field_only.map(&:camelize)
  end
  unless field_except.empty?
    name_segments << 'Except'
    name_segments << field_except.map(&:camelize)
  end
  name_segments.join
end

#ts_typeObject



333
334
335
# File 'lib/ar_serializer/graphql/types.rb', line 333

def ts_type
  "Type#{name}"
end