Class: ArSerializer::GraphQL::ScalarTypeClass

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

#association_type, #description, #fields, from, #of_type, #validate!

Constructor Details

#initialize(type) ⇒ ScalarTypeClass

Returns a new instance of ScalarTypeClass.



178
179
180
# File 'lib/ar_serializer/graphql/types.rb', line 178

def initialize(type)
  @type = type
end

Instance Method Details

#collect_types(types) ⇒ Object



205
206
207
# File 'lib/ar_serializer/graphql/types.rb', line 205

def collect_types(types)
  types[name] = true
end

#gql_typeObject



209
210
211
# File 'lib/ar_serializer/graphql/types.rb', line 209

def gql_type
  type
end

#kindObject



182
183
184
# File 'lib/ar_serializer/graphql/types.rb', line 182

def kind
  'SCALAR'
end

#nameObject



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/ar_serializer/graphql/types.rb', line 186

def name
  case type
  when String, :string
    :string
  when Integer, :int
    :int
  when Float, :float
    :float
  when true, false, :boolean
    :boolean
  when :other
    :other
  when :unknown
    :unknown
  else
    :any
  end
end

#sampleObject



213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/ar_serializer/graphql/types.rb', line 213

def sample
  case ts_type
  when 'number'
    0
  when 'string'
    ''
  when 'boolean'
    true
  when 'any', 'unknown'
    nil
  else
    type
  end
end

#ts_typeObject



228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/ar_serializer/graphql/types.rb', line 228

def ts_type
  case type
  when :int, :float
    'number'
  when :string, :number, :boolean, :unknown
    type.to_s
  when Symbol
    'any'
  else
    type.to_json
  end
end