Module: RuboCop::Cop::GemspecHelp

Overview

Common functionality for checking gem declarations.

Instance Method Summary collapse

Instance Method Details

#assignment_method_declarations(node) ⇒ Object



30
31
32
33
# File 'lib/rubocop/cop/mixin/gemspec_help.rb', line 30

def_node_search :assignment_method_declarations, <<~PATTERN
  (send
    (lvar {#match_block_variable_name? :_1 :it}) _ ...)
PATTERN

#gem_specification(node) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/rubocop/cop/mixin/gemspec_help.rb', line 20

def_node_search :gem_specification, <<~PATTERN
  (block
    (send
      (const
        (const {cbase nil?} :Gem) :Specification) :new)
    (args
      (arg $_)) ...)
PATTERN

#gem_specification?(node) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/rubocop/cop/mixin/gemspec_help.rb', line 10

def_node_matcher :gem_specification?, <<~PATTERN
  (block
    (send
      (const
        (const {cbase nil?} :Gem) :Specification) :new)
    (args
      (arg $_)) ...)
PATTERN

#indexed_assignment_method_declarations(node) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/rubocop/cop/mixin/gemspec_help.rb', line 36

def_node_search :indexed_assignment_method_declarations, <<~PATTERN
  (send
    (send (lvar {#match_block_variable_name? :_1 :it}) _)
    :[]=
    literal?
    _
  )
PATTERN

#match_block_variable_name?(receiver_name) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
# File 'lib/rubocop/cop/mixin/gemspec_help.rb', line 45

def match_block_variable_name?(receiver_name)
  gem_specification(processed_source.ast) do |block_variable_name|
    return block_variable_name == receiver_name
  end
end