Refactor common bits to abstract provider superclass
This commit is contained in:
parent
7d4244b35e
commit
2926aca2e4
23
lib/puppet/provider/vcsrepo.rb
Normal file
23
lib/puppet/provider/vcsrepo.rb
Normal file
@ -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
|
@ -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"
|
desc "Supports CVS repositories/workspaces"
|
||||||
|
|
||||||
commands :cvs => 'cvs'
|
commands :cvs => 'cvs'
|
||||||
@ -74,14 +76,4 @@ Puppet::Type.type(:vcsrepo).provide(:cvs) do
|
|||||||
cvs('-d', path, 'init')
|
cvs('-d', path, 'init')
|
||||||
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
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
require 'tmpdir'
|
require 'puppet/provider/vcsrepo'
|
||||||
require 'digest/md5'
|
|
||||||
|
|
||||||
Puppet::Type.type(:vcsrepo).provide(:git) do
|
Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) do
|
||||||
desc "Supports Git repositories"
|
desc "Supports Git repositories"
|
||||||
|
|
||||||
commands :git => 'git'
|
commands :git => 'git'
|
||||||
@ -144,18 +143,4 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
|
|||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
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"
|
desc "Supports Subversion repositories"
|
||||||
|
|
||||||
commands :svn => 'svn',
|
commands :svn => 'svn',
|
||||||
@ -56,14 +58,4 @@ Puppet::Type.type(:vcsrepo).provide(:svn) do
|
|||||||
svnadmin(*args)
|
svnadmin(*args)
|
||||||
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
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user