class GraphqlRails::Attributes::AttributeNameParser

Parses attribute name and can generates graphql scalar type, grapqhl name and etc. based on that

Attributes

name[R]
options[R]

Public Class Methods

new(original_name, options: {}) click to toggle source
# File lib/graphql_rails/attributes/attribute_name_parser.rb, line 10
def initialize(original_name, options: {})
  name = original_name.to_s
  @required = !name['!'].nil?
  @name = name.tr('!', '')
  @options = options
end

Public Instance Methods

field_name() click to toggle source
# File lib/graphql_rails/attributes/attribute_name_parser.rb, line 17
def field_name
  @field_name ||= \
    if original_format?
      preprocesed_name
    else
      preprocesed_name.camelize(:lower)
    end
end
graphql_type() click to toggle source
# File lib/graphql_rails/attributes/attribute_name_parser.rb, line 26
def graphql_type
  @graphql_type ||= \
    case name
    when 'id', /_id\Z/
      GraphQL::Types::ID
    when /\?\Z/
      GraphQL::Types::Boolean
    else
      GraphQL::Types::String
    end
end
required?() click to toggle source
# File lib/graphql_rails/attributes/attribute_name_parser.rb, line 38
def required?
  @required
end

Private Instance Methods

original_format?() click to toggle source
# File lib/graphql_rails/attributes/attribute_name_parser.rb, line 46
def original_format?
  options[:input_format] == :original || options[:attribute_name_format] == :original
end
preprocesed_name() click to toggle source
# File lib/graphql_rails/attributes/attribute_name_parser.rb, line 50
def preprocesed_name
  if name.end_with?('?')
    "is_#{name.remove(/\?\Z/)}"
  else
    name
  end
end