Class: ArSerializer::GraphQL::ScalarTypeClass

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

Instance Attribute Summary

Attributes inherited from TypeClass

#type

Instance Method Summary collapse

Methods inherited from TypeClass

#association_type, #description, #fields, from, #of_type

Constructor Details

#initialize(type) ⇒ ScalarTypeClass

Returns a new instance of ScalarTypeClass.



176
177
178
# File 'lib/ar_serializer/graphql/types.rb', line 176

def initialize(type)
  @type = type
end

Instance Method Details

#collect_types(types) ⇒ Object



201
202
203
# File 'lib/ar_serializer/graphql/types.rb', line 201

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

#gql_typeObject



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

def gql_type = type

#kindObject



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

def kind = 'SCALAR'

#nameObject



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/ar_serializer/graphql/types.rb', line 182

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

#ts_typeObject



207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/ar_serializer/graphql/types.rb', line 207

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