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



339
340
341
# File 'lib/ar_serializer/graphql/types.rb', line 339

def == t
  eql? t
end

#association_typeObject



323
324
325
# File 'lib/ar_serializer/graphql/types.rb', line 323

def association_type
  self
end

#collect_types(types) ⇒ Object



317
318
319
320
321
# File 'lib/ar_serializer/graphql/types.rb', line 317

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

#compare_elementsObject



343
344
345
# File 'lib/ar_serializer/graphql/types.rb', line 343

def compare_elements
  [type, field_only, field_except]
end

#eql?(t) ⇒ Boolean

Returns:

  • (Boolean)


335
336
337
# File 'lib/ar_serializer/graphql/types.rb', line 335

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

#field_exceptObject



288
289
290
# File 'lib/ar_serializer/graphql/types.rb', line 288

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

#field_onlyObject



284
285
286
# File 'lib/ar_serializer/graphql/types.rb', line 284

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

#fieldsObject



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

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



327
328
329
# File 'lib/ar_serializer/graphql/types.rb', line 327

def gql_type
  name
end

#hashObject



347
348
349
# File 'lib/ar_serializer/graphql/types.rb', line 347

def hash
  compare_elements.hash
end

#kindObject



292
293
294
# File 'lib/ar_serializer/graphql/types.rb', line 292

def kind
  'OBJECT'
end

#nameObject



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

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



331
332
333
# File 'lib/ar_serializer/graphql/types.rb', line 331

def ts_type
  "Type#{name}"
end