Class: RuboCop::Cop::CopStore

Inherits:
Array
  • Object
show all
Defined in:
lib/rubocop/cop/cop.rb

Overview

Store for all cops with helper functions

Instance Method Summary collapse

Instance Method Details

#cop_name_with_namespace(name, origin, basename, found_ns) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/rubocop/cop/cop.rb', line 39

def cop_name_with_namespace(name, origin, basename, found_ns)
  if name != basename && found_ns != File.dirname(name).to_sym
    warn "#{origin}: #{name} has the wrong namespace - should be " \
         "#{found_ns}"
  end
  "#{found_ns}/#{basename}"
end

#qualified_cop_name(name, origin) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubocop/cop/cop.rb', line 25

def qualified_cop_name(name, origin)
  @cop_names ||= Set.new(map(&:cop_name))
  basename = File.basename(name)
  found_ns = types.map(&:capitalize).select do |ns|
    @cop_names.include?("#{ns}/#{basename}")
  end

  case found_ns.size
  when 0 then name # No namespace found. Deal with it later in caller.
  when 1 then cop_name_with_namespace(name, origin, basename, found_ns[0])
  else fail AmbiguousCopName, "`#{basename}` used in #{origin}"
  end
end

#typesArray<String>

Returns list of types for current cops.

Returns:

  • (Array<String>)

    list of types for current cops.



10
11
12
13
# File 'lib/rubocop/cop/cop.rb', line 10

def types
  @types = map(&:cop_type).uniq! unless defined? @types
  @types
end

#with_type(type) ⇒ Array<Cop>

Returns Cops for that specific type.

Returns:

  • (Array<Cop>)

    Cops for that specific type.



16
17
18
# File 'lib/rubocop/cop/cop.rb', line 16

def with_type(type)
  CopStore.new(select { |c| c.cop_type == type })
end

#without_type(type) ⇒ Array<Cop>

Returns Cops not for a specific type.

Returns:

  • (Array<Cop>)

    Cops not for a specific type.



21
22
23
# File 'lib/rubocop/cop/cop.rb', line 21

def without_type(type)
  CopStore.new(reject { |c| c.cop_type == type })
end