require 'hrw/scanner' module Hrw # # To detect which platform used by current project # module Detector # # Errors # class MultipleChoiceError < StandardError; end # # Constants # DETECTABLE_FILES = { 'Gemfile.lock': Scanner::Gemfile }.freeze # Detect package manager in root dir # # @param [String] root root dir for project # @return [Hrw::Scanner] scanner def self.detect(root = Dir.pwd) files = Dir['*', base: root].map { |file| File.basename(file).to_sym } pkg_files = DETECTABLE_FILES.keys & files if pkg_files.empty? nil elsif pkg_files.size > 1 raise MultipleChoiceError else file = pkg_files.first DETECTABLE_FILES[file].new(root, file.to_s) end end end end