class GraphqlRails::Attributes::Attribute

contains info about single graphql attribute

Attributes

attributes[R]
initial_name[R]
initial_type[R]

Public Class Methods

new(name, type = nil, description: nil, property: name, required: nil, options: {}) click to toggle source

rubocop:disable Metrics/ParameterLists

# File lib/graphql_rails/attributes/attribute.rb, line 17
def initialize(name, type = nil, description: nil, property: name, required: nil, options: {})
  @initial_type = type
  @initial_name = name
  @options = options
  @description = description
  @property = property.to_s
  @required = required
  @attributes ||= {}
end

Public Instance Methods

argument_args() click to toggle source
# File lib/graphql_rails/attributes/attribute.rb, line 72
def argument_args
  [
    field_name,
    type_parser.type_arg,
    {
      description: description,
      required: required?
    }
  ]
end
description(new_description = nil) click to toggle source
# File lib/graphql_rails/attributes/attribute.rb, line 35
def description(new_description = nil)
  return @description if new_description.nil?

  @description = new_description
  self
end
field_args() click to toggle source
# File lib/graphql_rails/attributes/attribute.rb, line 56
def field_args
  [
    field_name,
    type_parser.type_arg,
    *description
  ]
end
field_options() click to toggle source
# File lib/graphql_rails/attributes/attribute.rb, line 64
def field_options
  {
    method: property.to_sym,
    null: optional?,
    camelize: camelize?
  }
end
options(new_options = {}) click to toggle source
# File lib/graphql_rails/attributes/attribute.rb, line 49
def options(new_options = {})
  return @options if new_options.blank?

  @options = new_options
  self
end
property(new_property = nil) click to toggle source
# File lib/graphql_rails/attributes/attribute.rb, line 42
def property(new_property = nil)
  return @property if new_property.nil?

  @property = new_property.to_s
  self
end
type(new_type = nil) click to toggle source

rubocop:enable Metrics/ParameterLists

# File lib/graphql_rails/attributes/attribute.rb, line 28
def type(new_type = nil)
  return @initial_type if new_type.nil?

  @initial_type = new_type
  self
end

Private Instance Methods

camelize?() click to toggle source
# File lib/graphql_rails/attributes/attribute.rb, line 89
def camelize?
  options[:input_format] != :original && options[:attribute_name_format] != :original
end