Sha256: f83570c83165959df3a620eb17231a73ac512f67c287dd70e80b92f31e62332f
Contents?: true
Size: 903 Bytes
Versions: 7
Compression:
Stored size: 903 Bytes
Contents
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, 'Pipfile.lock': Scanner::Pipfile, 'package-lock.json': Scanner::PackageLock }.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
Version data entries
7 entries across 7 versions & 1 rubygems