Module: RuboCop::Packaging::LibHelperModule

Overview

This helper module extracts the methods which can be used in other cop classes.

Instance Method Summary collapse

Instance Method Details

#inspected_file_falls_in_lib?Boolean

This method determines if that call is made from the “lib” directory.

Returns:

  • (Boolean)


25
26
27
# File 'lib/rubocop/packaging/lib_helper_module.rb', line 25

def inspected_file_falls_in_lib?
  @file_path.start_with?("#{root_dir}/lib")
end

#inspected_file_is_gemspec?Boolean

This method determines if that call is made from the “gemspec” file.

Returns:

  • (Boolean)


30
31
32
# File 'lib/rubocop/packaging/lib_helper_module.rb', line 30

def inspected_file_is_gemspec?
  @file_path.end_with?("gemspec")
end

#inspected_file_is_not_in_lib_or_gemspec?Boolean

This method determines if the inspected file is not in lib/ or isn’t a gemspec file.

Returns:

  • (Boolean)


36
37
38
# File 'lib/rubocop/packaging/lib_helper_module.rb', line 36

def inspected_file_is_not_in_lib_or_gemspec?
  !inspected_file_falls_in_lib? && !inspected_file_is_gemspec?
end

#root_dirObject

For determining the root directory of the project.



9
10
11
# File 'lib/rubocop/packaging/lib_helper_module.rb', line 9

def root_dir
  RuboCop::ConfigFinder.project_root
end

#target_falls_in_lib?(str) ⇒ Boolean

This method determines if the calls are made to the “lib” directory.

Returns:

  • (Boolean)


14
15
16
# File 'lib/rubocop/packaging/lib_helper_module.rb', line 14

def target_falls_in_lib?(str)
  File.expand_path(str, @file_directory).start_with?("#{root_dir}/lib")
end

#target_falls_in_lib_using_file?(str) ⇒ Boolean

This method determines if the calls (using the __FILE__ argument) are made to the “lib” directory.

Returns:

  • (Boolean)


20
21
22
# File 'lib/rubocop/packaging/lib_helper_module.rb', line 20

def target_falls_in_lib_using_file?(str)
  File.expand_path(str, @file_path).start_with?("#{root_dir}/lib")
end