Module: RuboCop::Cop::IndexMethod

Included in:
Rails::IndexBy, Rails::IndexWith
Defined in:
lib/rubocop/cop/mixin/index_method.rb

Overview

Common functionality for Rails/IndexBy and Rails/IndexWith

Defined Under Namespace

Classes: Autocorrection, Captures

Constant Summary collapse

RESTRICT_ON_SEND =

rubocop:disable Metrics/ModuleLength

i[each_with_object to_h map collect []].freeze

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object Also known as: on_numblock, on_itblock



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rubocop/cop/mixin/index_method.rb', line 74

def on_block(node)
  on_bad_each_with_object(node) do |*match|
    handle_possible_offense(node, match, 'each_with_object')
  end

  return if target_ruby_version < 2.6

  on_bad_to_h(node) do |*match|
    handle_possible_offense(node, match, 'to_h { ... }')
  end
end

#on_csend(node) ⇒ Object



99
100
101
102
103
# File 'lib/rubocop/cop/mixin/index_method.rb', line 99

def on_csend(node)
  on_bad_map_to_h(node) do |*match|
    handle_possible_offense(node, match, 'map { ... }.to_h')
  end
end

#on_send(node) ⇒ Object



89
90
91
92
93
94
95
96
97
# File 'lib/rubocop/cop/mixin/index_method.rb', line 89

def on_send(node)
  on_bad_map_to_h(node) do |*match|
    handle_possible_offense(node, match, 'map { ... }.to_h')
  end

  on_bad_hash_brackets_map(node) do |*match|
    handle_possible_offense(node, match, 'Hash[map { ... }]')
  end
end