Class: RuboCop::GraphQL::Field::Kwargs

Inherits:
Object
  • Object
show all
Extended by:
NodePattern::Macros
Defined in:
lib/rubocop/graphql/field/kwargs.rb

Instance Method Summary collapse

Constructor Details

#initialize(field_node) ⇒ Kwargs

Returns a new instance of Kwargs.



54
55
56
# File 'lib/rubocop/graphql/field/kwargs.rb', line 54

def initialize(field_node)
  @nodes = field_kwargs(field_node) || []
end

Instance Method Details

#aliasObject



66
67
68
# File 'lib/rubocop/graphql/field/kwargs.rb', line 66

def alias
  @alias ||= @nodes.map { |kwarg| alias_kwarg(kwarg) }.compact.first
end

#alias_kwarg(node) ⇒ Object



30
31
32
# File 'lib/rubocop/graphql/field/kwargs.rb', line 30

def_node_matcher :alias_kwarg, <<~PATTERN
  (pair (sym :alias) (sym $ _))
PATTERN

#camelizeObject



70
71
72
# File 'lib/rubocop/graphql/field/kwargs.rb', line 70

def camelize
  @nodes.find { |kwarg| camelize_kwarg?(kwarg) }
end

#camelize_kwarg?(node) ⇒ Object



50
51
52
# File 'lib/rubocop/graphql/field/kwargs.rb', line 50

def_node_matcher :camelize_kwarg?, <<~PATTERN
  (pair (sym :camelize) ...)
PATTERN

#descriptionObject



78
79
80
# File 'lib/rubocop/graphql/field/kwargs.rb', line 78

def description
  @nodes.find { |kwarg| description_kwarg?(kwarg) }
end

#description_kwarg?(node) ⇒ Object



40
41
42
# File 'lib/rubocop/graphql/field/kwargs.rb', line 40

def_node_matcher :description_kwarg?, <<~PATTERN
  (pair (sym :description) ...)
PATTERN

#field_kwargs(node) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/rubocop/graphql/field/kwargs.rb', line 10

def_node_matcher :field_kwargs, <<~PATTERN
  (send nil? :field
    ...
    (hash
      $...
    )
  )
PATTERN

#hash_keyObject



74
75
76
# File 'lib/rubocop/graphql/field/kwargs.rb', line 74

def hash_key
  @nodes.find { |kwarg| hash_key_kwarg?(kwarg) }
end

#hash_key_kwarg?(node) ⇒ Object



35
36
37
# File 'lib/rubocop/graphql/field/kwargs.rb', line 35

def_node_matcher :hash_key_kwarg?, <<~PATTERN
  (pair (sym :hash_key) ...)
PATTERN

#methodObject



62
63
64
# File 'lib/rubocop/graphql/field/kwargs.rb', line 62

def method
  @nodes.find { |kwarg| method_kwarg?(kwarg) }
end

#method_kwarg?(node) ⇒ Object



25
26
27
# File 'lib/rubocop/graphql/field/kwargs.rb', line 25

def_node_matcher :method_kwarg?, <<~PATTERN
  (pair (sym :method) ...)
PATTERN

#resolverObject



58
59
60
# File 'lib/rubocop/graphql/field/kwargs.rb', line 58

def resolver
  @nodes.find { |kwarg| resolver_kwarg?(kwarg) }
end

#resolver_kwarg?(node) ⇒ Object



20
21
22
# File 'lib/rubocop/graphql/field/kwargs.rb', line 20

def_node_matcher :resolver_kwarg?, <<~PATTERN
  (pair (sym :resolver) ...)
PATTERN

#resolver_method_nameObject



82
83
84
85
# File 'lib/rubocop/graphql/field/kwargs.rb', line 82

def resolver_method_name
  @resolver_method_name ||=
    @nodes.flat_map { |kwarg| resolver_method_option(kwarg) }.compact.first
end

#resolver_method_option(node) ⇒ Object



45
46
47
# File 'lib/rubocop/graphql/field/kwargs.rb', line 45

def_node_matcher :resolver_method_option, <<~PATTERN
  (pair (sym :resolver_method) (sym $...))
PATTERN