123456789_123456789_123456789_123456789_123456789_

Class: GraphQL::Client::Schema::EnumType

Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Module
Instance Chain:
self, BaseType, Module
Inherits: Module
  • Object
Defined in: lib/graphql/client/schema/enum_type.rb

Class Method Summary

Instance Attribute Summary

BaseType - Included

#schema_module

Internal: Get owner schema Module container.

#type

Public: Get associated GraphQL::BaseType with for this class.

Instance Method Summary

BaseType - Included

#cast

Internal: Cast JSON value to wrapped value.

#to_list_type

Internal: Get list wrapper of this type class.

#to_non_null_type

Internal: Get non-nullable wrapper of this type class.

Constructor Details

.new(type) ⇒ EnumType

Internal: Construct enum wrapper from another GraphQL::EnumType.

type - GraphQL::EnumType instance

[ GitHub ]

  
# File 'lib/graphql/client/schema/enum_type.rb', line 43

def initialize(type)
  unless type.kind.enum?
    raise "expected type to be an Enum, but was #{type.class}"
  end

  @type = type
  @values = {}

  all_values = type.values.keys
  comparison_set = all_values.map { |s| -s.downcase }.to_set

  all_values.each do |value|
    str = EnumValue.new(-value, -value.downcase, comparison_set).freeze
    const_set(value, str) if value =~ /^[A-Z]/
    @values[str.to_s] = str
  end

  @values.freeze
end

Instance Method Details

#[](value)

[ GitHub ]

  
# File 'lib/graphql/client/schema/enum_type.rb', line 67

def [](value)
  @values[value]
end

#cast(value, _errors = nil)

Internal: Cast JSON value to the enumeration’s corresponding constant string instance

with the convenience predicate methods.

values - JSON value errors - ::GraphQL::Client::Errors instance

Returns String or nil.

[ GitHub ]

  
# File 'lib/graphql/client/schema/enum_type.rb', line 78

def cast(value, _errors = nil)
  case value
  when String
    raise Error, "unexpected enum value #{value}" unless @values.key?(value)
    @values[value]
  when NilClass
    value
  else
    raise InvariantError, "expected value to be a String, but was #{value.class}"
  end
end

#define_class(definition, ast_nodes)

[ GitHub ]

  
# File 'lib/graphql/client/schema/enum_type.rb', line 63

def define_class(definition, ast_nodes)
  self
end