Class: GraphqlRails::Attributes::AttributeNameParser
- Inherits:
-
Object
- Object
- GraphqlRails::Attributes::AttributeNameParser
- Defined in:
- lib/graphql_rails/attributes/attribute_name_parser.rb
Overview
Parses attribute name and can generates graphql scalar type, graphql name and etc. based on that
Instance Method Summary collapse
- #field_name ⇒ Object
- #graphql_type ⇒ Object
-
#initialize(original_name, options: {}) ⇒ AttributeNameParser
constructor
A new instance of AttributeNameParser.
- #name ⇒ Object
- #required? ⇒ Boolean
Constructor Details
#initialize(original_name, options: {}) ⇒ AttributeNameParser
Returns a new instance of AttributeNameParser.
8 9 10 11 |
# File 'lib/graphql_rails/attributes/attribute_name_parser.rb', line 8 def initialize(original_name, options: {}) @original_name = original_name.to_s @options = end |
Instance Method Details
#field_name ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/graphql_rails/attributes/attribute_name_parser.rb', line 13 def field_name @field_name ||= \ if original_format? preprocessed_name else preprocessed_name.camelize(:lower) end end |
#graphql_type ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/graphql_rails/attributes/attribute_name_parser.rb', line 22 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 |
#name ⇒ Object
38 39 40 |
# File 'lib/graphql_rails/attributes/attribute_name_parser.rb', line 38 def name @name ||= original_name.tr('!', '') end |
#required? ⇒ Boolean
34 35 36 |
# File 'lib/graphql_rails/attributes/attribute_name_parser.rb', line 34 def required? original_name['!'].present? || original_name.end_with?('?') end |