diff options
author | Bruce Williams <bruce@codefluency.com> | 2010-03-13 12:04:57 -0800 |
---|---|---|
committer | Bruce Williams <bruce@codefluency.com> | 2010-03-13 12:04:57 -0800 |
commit | 2926aca2e482b00ecaa616003f1096578f93c035 (patch) | |
tree | 7d159646d311cfa79bfeede6b930166b59427f13 | |
parent | 7d4244b35e72904e30130cad6d2258f901c16f1a (diff) | |
download | puppet-vcsrepo-2926aca2e482b00ecaa616003f1096578f93c035.tar.gz puppet-vcsrepo-2926aca2e482b00ecaa616003f1096578f93c035.tar.bz2 |
Refactor common bits to abstract provider superclass
-rw-r--r-- | lib/puppet/provider/vcsrepo.rb | 23 | ||||
-rw-r--r-- | lib/puppet/provider/vcsrepo/cvs.rb | 14 | ||||
-rw-r--r-- | lib/puppet/provider/vcsrepo/git.rb | 19 | ||||
-rw-r--r-- | lib/puppet/provider/vcsrepo/svn.rb | 16 |
4 files changed, 32 insertions, 40 deletions
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 |