From 2926aca2e482b00ecaa616003f1096578f93c035 Mon Sep 17 00:00:00 2001 From: Bruce Williams Date: Sat, 13 Mar 2010 12:04:57 -0800 Subject: Refactor common bits to abstract provider superclass --- lib/puppet/provider/vcsrepo.rb | 23 +++++++++++++++++++++++ lib/puppet/provider/vcsrepo/cvs.rb | 14 +++----------- lib/puppet/provider/vcsrepo/git.rb | 19 ++----------------- lib/puppet/provider/vcsrepo/svn.rb | 16 ++++------------ 4 files changed, 32 insertions(+), 40 deletions(-) create mode 100644 lib/puppet/provider/vcsrepo.rb diff --git a/lib/puppet/provider/vcsrepo.rb b/lib/puppet/provider/vcsrepo.rb new file mode 100644 index 0000000..c560e93 --- /dev/null +++ b/lib/puppet/provider/vcsrepo.rb @@ -0,0 +1,23 @@ +require 'tmpdir' +require 'digest/md5' + +# Abstract +class Puppet::Provider::Vcsrepo < Puppet::Provider + + private + + # Note: We don't rely on Dir.chdir's behavior of automatically returning the + # value of the last statement -- for easier stubbing. + def at_path(&block) #:nodoc: + value = nil + Dir.chdir(@resource.value(:path)) do + value = yield + end + value + end + + def tempdir + @tempdir ||= File.join(Dir.tmpdir, 'vcsrepo-' + Digest::MD5.hexdigest(@resource.value(:path))) + end + +end diff --git a/lib/puppet/provider/vcsrepo/cvs.rb b/lib/puppet/provider/vcsrepo/cvs.rb index 68d22c1..58018d3 100644 --- a/lib/puppet/provider/vcsrepo/cvs.rb +++ b/lib/puppet/provider/vcsrepo/cvs.rb @@ -1,4 +1,6 @@ -Puppet::Type.type(:vcsrepo).provide(:cvs) do +require 'puppet/provider/vcsrepo' + +Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo) do desc "Supports CVS repositories/workspaces" commands :cvs => 'cvs' @@ -74,14 +76,4 @@ Puppet::Type.type(:vcsrepo).provide(:cvs) do cvs('-d', path, 'init') end - # Note: We don't rely on Dir.chdir's behavior of automatically returning the - # value of the last statement -- for easier stubbing. - def at_path(&block) #:nodoc: - value = nil - Dir.chdir(@resource.value(:path)) do - value = yield - end - value - end - end diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index 2ea146f..99477a0 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -1,7 +1,6 @@ -require 'tmpdir' -require 'digest/md5' +require 'puppet/provider/vcsrepo' -Puppet::Type.type(:vcsrepo).provide(:git) do +Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) do desc "Supports Git repositories" commands :git => 'git' @@ -144,18 +143,4 @@ Puppet::Type.type(:vcsrepo).provide(:git) do end end - # Note: We don't rely on Dir.chdir's behavior of automatically returning the - # value of the last statement -- for easier stubbing. - def at_path(&block) #:nodoc: - value = nil - Dir.chdir(@resource.value(:path)) do - value = yield - end - value - end - - def tempdir - @tempdir ||= File.join(Dir.tmpdir, 'vcsrepo-' + Digest::MD5.hexdigest(@resource.value(:path))) - end - end diff --git a/lib/puppet/provider/vcsrepo/svn.rb b/lib/puppet/provider/vcsrepo/svn.rb index c85ffa4..97c7fcb 100644 --- a/lib/puppet/provider/vcsrepo/svn.rb +++ b/lib/puppet/provider/vcsrepo/svn.rb @@ -1,11 +1,13 @@ -Puppet::Type.type(:vcsrepo).provide(:svn) do +require 'puppet/provider/vcsrepo' + +Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo) do desc "Supports Subversion repositories" commands :svn => 'svn', :svnadmin => 'svnadmin' defaultfor :svn => :exists - + def create if !@resource.value(:source) create_repository(@resource.value(:path)) @@ -56,14 +58,4 @@ Puppet::Type.type(:vcsrepo).provide(:svn) do svnadmin(*args) end - # Note: We don't rely on Dir.chdir's behavior of automatically returning the - # value of the last statement -- for easier stubbing. - def at_path(&block) #:nodoc: - value = nil - Dir.chdir(@resource.value(:path)) do - value = yield - end - value - end - end -- cgit v1.2.3