Class: ArSerializer::GraphQL::SerializableTypeClass

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

Instance Attribute Summary collapse

Attributes inherited from TypeClass

#type

Instance Method Summary collapse

Methods inherited from TypeClass

#description, from, #of_type

Constructor Details

#initialize(type, only = nil, except = nil) ⇒ SerializableTypeClass

Returns a new instance of SerializableTypeClass.



263
264
265
266
267
# File 'lib/ar_serializer/graphql/types.rb', line 263

def initialize(type, only = nil, except = nil)
  super type
  @only = only
  @except = except
end

Instance Attribute Details

#exceptObject (readonly)

Returns the value of attribute except.



261
262
263
# File 'lib/ar_serializer/graphql/types.rb', line 261

def except
  @except
end

#onlyObject (readonly)

Returns the value of attribute only.



261
262
263
# File 'lib/ar_serializer/graphql/types.rb', line 261

def only
  @only
end

Instance Method Details

#==(t) ⇒ Object



316
317
318
# File 'lib/ar_serializer/graphql/types.rb', line 316

def == t
  eql? t
end

#association_typeObject



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

def association_type = self

#collect_types(types) ⇒ Object



300
301
302
303
304
# File 'lib/ar_serializer/graphql/types.rb', line 300

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

#compare_elementsObject



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

def compare_elements
  [type, field_only, field_except]
end

#eql?(t) ⇒ Boolean

Returns:

  • (Boolean)


312
313
314
# File 'lib/ar_serializer/graphql/types.rb', line 312

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

#field_exceptObject



273
274
275
# File 'lib/ar_serializer/graphql/types.rb', line 273

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

#field_onlyObject



269
270
271
# File 'lib/ar_serializer/graphql/types.rb', line 269

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

#fieldsObject



292
293
294
295
296
297
298
# File 'lib/ar_serializer/graphql/types.rb', line 292

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



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

def gql_type = name

#hashObject



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

def hash
  compare_elements.hash
end

#kindObject



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

def kind = 'OBJECT'

#nameObject



279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/ar_serializer/graphql/types.rb', line 279

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



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

def ts_type = "Type#{name}"