class RuboCop::Cop::CopStore

Store for all cops with helper functions

Public Instance Methods

cop_name_with_namespace(name, origin, basename, found_ns) click to toggle source
# File lib/rubocop/cop/cop.rb, line 40
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) click to toggle source
# File lib/rubocop/cop/cop.rb, line 24
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 raise AmbiguousCopName,
             "Ambiguous cop name `#{basename}` used in"                     "#{origin} needs namespace qualifier."
  end
end
types() click to toggle source

@return [Array<String>] list of types for current cops.

# File lib/rubocop/cop/cop.rb, line 10
def types
  @types ||= map(&:cop_type).uniq!
end
with_type(type) click to toggle source

@return [Array<Cop>] Cops for that specific type.

# File lib/rubocop/cop/cop.rb, line 15
def with_type(type)
  CopStore.new(select { |c| c.cop_type == type })
end
without_type(type) click to toggle source

@return [Array<Cop>] Cops not for a specific type.

# File lib/rubocop/cop/cop.rb, line 20
def without_type(type)
  CopStore.new(reject { |c| c.cop_type == type })
end