class Apia::Definitions::Type
Public Class Methods
new(type)
click to toggle source
# File lib/apia/definitions/type.rb, line 7 def initialize(type) @type = type end
Public Instance Methods
argument_set?()
click to toggle source
Does this field return an argument set?
@return [Boolean]
# File lib/apia/definitions/type.rb, line 75 def argument_set? klass&.ancestors&.include?(Apia::ArgumentSet) end
cast(value, request: nil, path: [])
click to toggle source
Cast the given value into an response that can be sent to the consumer.
@param value [Object, nil] @param request [Apia::Request, nil] @return [Object, nil]
# File lib/apia/definitions/type.rb, line 43 def cast(value, request: nil, path: []) return nil if value.nil? if scalar? || enum? # If this is a scalar or an enum, we're going to just return the # value that they return. There's nothing complicated about them # and they return scalars. klass.cast(value) elsif object? # If this field returns an object, we'll go ahead and generate # the hash for the object at this point. object = klass.new(value) # If this item shouldn't be included. we'll return :skip which # will instruct the field set not to include it at all. return :skip unless object.include?(request) # Otherwise, we'll return the hash object.hash(request: request, path: path) elsif polymorph? # If the type is a polymorph and this value option = klass.option_for_value(value) option.cast(value, request: request, path: path) end end
enum?()
click to toggle source
Does this field return an enum?
@return [Boolean]
# File lib/apia/definitions/type.rb, line 89 def enum? klass&.ancestors&.include?(Apia::Enum) end
id()
click to toggle source
# File lib/apia/definitions/type.rb, line 11 def id klass&.definition&.id end
klass()
click to toggle source
# File lib/apia/definitions/type.rb, line 15 def klass if @type.is_a?(Symbol) || @type.is_a?(String) Scalars.fetch(@type.to_sym) else @type end end
object?()
click to toggle source
Does this field return an object?
@return [Boolean]
# File lib/apia/definitions/type.rb, line 96 def object? klass&.ancestors&.include?(Apia::Object) end
polymorph?()
click to toggle source
Does this field return a polymorph?
@return [Boolean]
# File lib/apia/definitions/type.rb, line 103 def polymorph? klass&.ancestors&.include?(Apia::Polymorph) end
scalar?()
click to toggle source
Does this field return a scalar?
@return [Boolean]
# File lib/apia/definitions/type.rb, line 82 def scalar? klass&.ancestors&.include?(Apia::Scalar) end
usable_for_argument?()
click to toggle source
Can this type be used for an argument?
@return [Boolean]
# File lib/apia/definitions/type.rb, line 33 def usable_for_argument? scalar? || enum? || argument_set? end
usable_for_field?()
click to toggle source
Can this type actually be used?
@return [Boolean]
# File lib/apia/definitions/type.rb, line 26 def usable_for_field? scalar? || object? || enum? || polymorph? end