Skip to content

Commit

Permalink
Merge pull request #136 from dafyddcrosby/pure_ruby_bw
Browse files Browse the repository at this point in the history
Have repo auto-detection lazily load repository libraries
  • Loading branch information
joshuamiller01 authored Nov 29, 2023
2 parents 9548304 + e02a7ca commit 396dd8f
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/between_meals/repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ def self.get(type, repo_path, logger)
exit(1)
end
logger.info('Trying to detect repo type')
require 'between_meals/repo/git'
require 'between_meals/repo/hg'
require 'between_meals/repo/svn'
[
BetweenMeals::Repo::Git,
BetweenMeals::Repo::Hg,
BetweenMeals::Repo::Svn,
].each do |klass|

{
'Hg' => 'between_meals/repo/hg',
'Svn' => 'between_meals/repo/svn',
'Git' => 'between_meals/repo/git',
}.each do |klass_name, req|
require req
klass = BetweenMeals::Repo.const_get(klass_name)
r = klass.new(repo_path, logger)
if r.exists?
logger.info("Repo found to be #{klass.to_s.split('::').last}")
Expand All @@ -60,15 +58,15 @@ def self.get(type, repo_path, logger)
end
logger.warn("Failed detecting repo type at #{repo_path}")
exit(1)
when 'hg'
require 'between_meals/repo/hg'
BetweenMeals::Repo::Hg.new(repo_path, logger)
when 'svn'
require 'between_meals/repo/svn'
BetweenMeals::Repo::Svn.new(repo_path, logger)
when 'git'
require 'between_meals/repo/git'
BetweenMeals::Repo::Git.new(repo_path, logger)
when 'hg'
require 'between_meals/repo/hg'
BetweenMeals::Repo::Hg.new(repo_path, logger)
else
fail "Do not know repo type #{type}"
end
Expand Down

0 comments on commit 396dd8f

Please sign in to comment.