Module: Stone::AST::FieldHelpers

Defined in:
lib/stone/ast.rb

Overview

Shared utilities for working with field annotations

Class Method Summary collapse

Class Method Details

.field_type_name(field) ⇒ Object

Get the string representation of a field's type



58
59
60
# File 'lib/stone/ast.rb', line 58

module_function def field_type_name(field)
  field[:type_name] || field[:type].to_s
end

.resolve_field_type(field, registry = Stone::Type::Registry) ⇒ Object

Resolve a field's annotation to a Stone::Type Returns nil if the type cannot be resolved



48
49
50
51
52
53
54
55
# File 'lib/stone/ast.rb', line 48

module_function def resolve_field_type(field, registry = Stone::Type::Registry)
  annotation = field[:type]
  if annotation.respond_to?(:to_type)
    annotation.to_type(registry)
  else
    registry.lookup(field[:type_name] || field[:type])
  end
end

.union_annotation?(annotation) ⇒ Boolean

Check if an annotation represents a union type



42
43
44
# File 'lib/stone/ast.rb', line 42

module_function def union_annotation?(annotation)
  annotation.is_a?(Stone::AST::UnionTypeAnnotation)
end