From 114d233940abfd60cc33f2ea13621c06a840fd24 Mon Sep 17 00:00:00 2001 From: Grey Baker Date: Sun, 1 Apr 2018 22:07:27 +0100 Subject: [PATCH] Add convenience methods for accessing version and requirement classes --- dependabot-core.gemspec | 2 +- lib/dependabot.rb | 1 + lib/dependabot/requirement.rb | 24 ++++++++++++++++ .../update_checkers/python/pip/requirement.rb | 1 + lib/dependabot/version.rb | 28 ++++++++++++++++++- 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 lib/dependabot/requirement.rb diff --git a/dependabot-core.gemspec b/dependabot-core.gemspec index 657d2f2d58..593d5335c0 100644 --- a/dependabot-core.gemspec +++ b/dependabot-core.gemspec @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "./lib/dependabot/version" +require "./lib/dependabot" Gem::Specification.new do |spec| spec.name = "dependabot-core" diff --git a/lib/dependabot.rb b/lib/dependabot.rb index fb0269bb85..58eafcb309 100644 --- a/lib/dependabot.rb +++ b/lib/dependabot.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true module Dependabot + VERSION = "0.52.29" end diff --git a/lib/dependabot/requirement.rb b/lib/dependabot/requirement.rb new file mode 100644 index 0000000000..09be1358f7 --- /dev/null +++ b/lib/dependabot/requirement.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require "dependabot/update_checkers/python/pip/requirement" +require "dependabot/update_checkers/java_script/npm_and_yarn/requirement" +require "dependabot/update_checkers/php/composer/requirement" +require "dependabot/update_checkers/elixir/hex/requirement" +require "dependabot/update_checkers/rust/cargo/requirement" + +module Dependabot + module Requirement + def self.for_package_manager(package_manager) + case package_manager + when "bundler", "maven", "submodules", "docker" then Gem::Requirement + when "npm_and_yarn" + UpdateCheckers::JavaScript::NpmAndYarn::Requirement + when "pip" then UpdateCheckers::Python::Pip::Requirement + when "composer" then UpdateCheckers::Php::Composer::Requirement + when "hex" then UpdateCheckers::Elixir::Hex::Requirement + when "cargo" then UpdateCheckers::Rust::Cargo::Requirement + else raise "Unsupported package_manager #{package_manager}" + end + end + end +end diff --git a/lib/dependabot/update_checkers/python/pip/requirement.rb b/lib/dependabot/update_checkers/python/pip/requirement.rb index 330d408676..655892dae6 100644 --- a/lib/dependabot/update_checkers/python/pip/requirement.rb +++ b/lib/dependabot/update_checkers/python/pip/requirement.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require "dependabot/update_checkers/python/pip" require "dependabot/update_checkers/python/pip/version" module Dependabot diff --git a/lib/dependabot/version.rb b/lib/dependabot/version.rb index 58eafcb309..7e68258ead 100644 --- a/lib/dependabot/version.rb +++ b/lib/dependabot/version.rb @@ -1,5 +1,31 @@ # frozen_string_literal: true +# These must be loaded first, or we get load order errors +require "dependabot/update_checkers/python/pip/requirement" +require "dependabot/update_checkers/elixir/hex/requirement" + +require "dependabot/update_checkers/python/pip/version" +require "dependabot/update_checkers/java/maven/version" +require "dependabot/update_checkers/java_script/npm_and_yarn/version" +require "dependabot/update_checkers/php/composer/version" +require "dependabot/update_checkers/elixir/hex/version" +require "dependabot/update_checkers/rust/cargo/version" + module Dependabot - VERSION = "0.52.29" + module Version + # rubocop:disable Metrics/CyclomaticComplexity + def self.for_package_manager(package_manager) + case package_manager + when "bundler", "submodules", "docker" then Gem::Version + when "maven" then UpdateCheckers::Java::Maven::Version + when "npm_and_yarn" then UpdateCheckers::JavaScript::NpmAndYarn::Version + when "pip" then UpdateCheckers::Python::Pip::Version + when "composer" then UpdateCheckers::Php::Composer::Version + when "hex" then UpdateCheckers::Elixir::Hex::Version + when "cargo" then UpdateCheckers::Rust::Cargo::Version + else raise "Unsupported package_manager #{package_manager}" + end + end + # rubocop:enable Metrics/CyclomaticComplexity + end end