Class: ArSerializer::GraphQL::SerializableTypeClass
- Inherits:
-
TypeClass
- Object
- TypeClass
- ArSerializer::GraphQL::SerializableTypeClass
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
#except ⇒ Object
Returns the value of attribute except.
261
262
263
|
# File 'lib/ar_serializer/graphql/types.rb', line 261
def except
@except
end
|
#only ⇒ Object
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_type ⇒ Object
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_elements ⇒ Object
320
321
322
|
# File 'lib/ar_serializer/graphql/types.rb', line 320
def compare_elements
[type, field_only, field_except]
end
|
#eql?(t) ⇒ 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_except ⇒ Object
273
274
275
|
# File 'lib/ar_serializer/graphql/types.rb', line 273
def field_except
[*except].map(&:to_s)
end
|
#field_only ⇒ Object
269
270
271
|
# File 'lib/ar_serializer/graphql/types.rb', line 269
def field_only
[*only].map(&:to_s)
end
|
#fields ⇒ Object
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_type ⇒ Object
308
|
# File 'lib/ar_serializer/graphql/types.rb', line 308
def gql_type = name
|
#hash ⇒ Object
324
325
326
|
# File 'lib/ar_serializer/graphql/types.rb', line 324
def hash
compare_elements.hash
end
|
#kind ⇒ Object
277
|
# File 'lib/ar_serializer/graphql/types.rb', line 277
def kind = 'OBJECT'
|
#name ⇒ Object
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_type ⇒ Object
310
|
# File 'lib/ar_serializer/graphql/types.rb', line 310
def ts_type = "Type#{name}"
|