1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
# frozen_string_literal: true
module RuboCop # :nodoc:
module Packaging # :nodoc:
# This helper module extracts the methods which can be used
# in other cop classes.
module LibHelperModule
# For determining the root directory of the project.
def root_dir
RuboCop::ConfigLoader.project_root
end
# This method determines if the calls are made to the "lib" directory.
def target_falls_in_lib?(str)
File.expand_path(str, @file_directory).start_with?("#{root_dir}/lib")
end
# This method determines if the calls (using the __FILE__ argument)
# are made to the "lib" directory.
def target_falls_in_lib_using_file?(str)
File.expand_path(str, @file_path).start_with?("#{root_dir}/lib")
end
# This method determines if that call is made *from* the "lib" directory.
def inspected_file_falls_in_lib?
@file_path.start_with?("#{root_dir}/lib")
end
# This method determines if that call is made *from* the "gemspec" file.
def inspected_file_is_gemspec?
@file_path.end_with?("gemspec")
end
# This method determines if the inspected file is not in lib/ or
# isn't a gemspec file.
def inspected_file_is_not_in_lib_or_gemspec?
!inspected_file_falls_in_lib? && !inspected_file_is_gemspec?
end
end
end
end
|