Class: RuboCop::GraphQL::Field
- Inherits:
-
Object
- Object
- RuboCop::GraphQL::Field
- Extended by:
- Forwardable, NodePattern::Macros
- Defined in:
- lib/rubocop/graphql/field.rb,
lib/rubocop/graphql/field/block.rb,
lib/rubocop/graphql/field/kwargs.rb
Defined Under Namespace
Constant Summary collapse
- RUBY_KEYWORDS =
These constants were extracted from graphql-ruby in lib/graphql/schema/member/has_fields.rb
%i[class module def undef begin rescue ensure end if unless then elsif else case when while until for break next redo retry in do return yield super self nil true false and or not alias defined? BEGIN END __LINE__ __FILE__].freeze
- GRAPHQL_RUBY_KEYWORDS =
%i[context object raw_value].freeze
- CONFLICT_FIELD_NAMES =
Set.new( GRAPHQL_RUBY_KEYWORDS + RUBY_KEYWORDS + Object.instance_methods )
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #block ⇒ Object
- #description ⇒ Object
- #field_description(node) ⇒ Object
- #field_name(node) ⇒ Object
- #field_with_body_name(node) ⇒ Object
-
#initialize(node) ⇒ Field
constructor
A new instance of Field.
- #kwargs ⇒ Object
- #name ⇒ Object
- #resolver_method_name ⇒ Object
- #schema_member ⇒ Object
- #underscore_name ⇒ Object
Constructor Details
#initialize(node) ⇒ Field
Returns a new instance of Field.
41 42 43 |
# File 'lib/rubocop/graphql/field.rb', line 41 def initialize(node) @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
39 40 41 |
# File 'lib/rubocop/graphql/field.rb', line 39 def node @node end |
Instance Method Details
#block ⇒ Object
72 73 74 |
# File 'lib/rubocop/graphql/field.rb', line 72 def block @block ||= Field::Block.new(@node.parent) end |
#description ⇒ Object
60 61 62 |
# File 'lib/rubocop/graphql/field.rb', line 60 def description @description ||= field_description(@node) || kwargs.description || block.description end |
#field_description(node) ⇒ Object
35 36 37 |
# File 'lib/rubocop/graphql/field.rb', line 35 def_node_matcher :field_description, <<~PATTERN (send nil? :field _ _ {(:str $_)|(:dstr $...)} ...) PATTERN |
#field_name(node) ⇒ Object
24 25 26 |
# File 'lib/rubocop/graphql/field.rb', line 24 def_node_matcher :field_name, <<~PATTERN (send nil? :field (:sym $_) ...) PATTERN |
#field_with_body_name(node) ⇒ Object
29 30 31 32 |
# File 'lib/rubocop/graphql/field.rb', line 29 def_node_matcher :field_with_body_name, <<~PATTERN (block (send nil? :field (:sym $_) ...)...) PATTERN |
#kwargs ⇒ Object
68 69 70 |
# File 'lib/rubocop/graphql/field.rb', line 68 def kwargs @kwargs ||= Field::Kwargs.new(@node) end |
#name ⇒ Object
45 46 47 |
# File 'lib/rubocop/graphql/field.rb', line 45 def name @name ||= field_name(@node) || field_with_body_name(@node) end |
#resolver_method_name ⇒ Object
64 65 66 |
# File 'lib/rubocop/graphql/field.rb', line 64 def resolver_method_name kwargs.resolver_method_name || name end |
#schema_member ⇒ Object
76 77 78 |
# File 'lib/rubocop/graphql/field.rb', line 76 def schema_member @schema_member ||= SchemaMember.new(root_node) end |
#underscore_name ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rubocop/graphql/field.rb', line 49 def underscore_name @underscore_name ||= begin word = name.to_s.dup word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') word.tr!("-", "_") word.downcase! word end end |