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.



170
171
172
# File 'lib/ar_serializer/graphql/types.rb', line 170

def initialize(type)
  @type = type
end

Instance Method Details

#collect_types(types) ⇒ Object



195
196
197
# File 'lib/ar_serializer/graphql/types.rb', line 195

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

#gql_typeObject



199
200
201
# File 'lib/ar_serializer/graphql/types.rb', line 199

def gql_type
  type
end

#kindObject



174
175
176
# File 'lib/ar_serializer/graphql/types.rb', line 174

def kind
  'SCALAR'
end

#nameObject



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/ar_serializer/graphql/types.rb', line 178

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

#sampleObject



203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/ar_serializer/graphql/types.rb', line 203

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

#ts_typeObject



218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/ar_serializer/graphql/types.rb', line 218

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