class RubyCritic::SourceLocator
Constants
- RUBY_EXTENSION
- RUBY_FILES
- RUBY_SHEBANG
Public Class Methods
new(paths)
click to toggle source
# File lib/rubycritic/source_locator.rb, line 12 def initialize(paths) @initial_paths = Array(paths) end
Public Instance Methods
pathnames()
click to toggle source
# File lib/rubycritic/source_locator.rb, line 20 def pathnames @pathnames ||= expand_paths end
paths()
click to toggle source
# File lib/rubycritic/source_locator.rb, line 16 def paths @paths ||= pathnames.map(&:to_s) end
Private Instance Methods
deduplicate_symlinks(path_list)
click to toggle source
# File lib/rubycritic/source_locator.rb, line 26 def deduplicate_symlinks(path_list) # sort the symlinks to the end so files are preferred path_list.sort_by! { |path| File.symlink?(path.cleanpath) ? 'z' : 'a' } if defined?(JRUBY_VERSION) require 'java' path_list.uniq! do |path| java.io.File.new(path.realpath.to_s).canonical_path end else path_list.uniq!(&:realpath) end end
expand_paths()
click to toggle source
# File lib/rubycritic/source_locator.rb, line 39 def expand_paths path_list = @initial_paths.flat_map do |path| if File.directory?(path) Pathname.glob(File.join(path, RUBY_FILES)) elsif File.exist?(path) && ruby_file?(path) Pathname.new(path) end end.compact deduplicate_symlinks(path_list) if Config.deduplicate_symlinks path_list.map(&:cleanpath) end
ruby_file?(path)
click to toggle source
# File lib/rubycritic/source_locator.rb, line 53 def ruby_file?(path) Config.ruby_extensions.include?(File.extname(path)) || File.open(path, &:gets).to_s.match?(RUBY_SHEBANG) end