diff options
| author | Luke Kanies <luke@madstop.com> | 2005-04-13 16:27:43 +0000 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2005-04-13 16:27:43 +0000 |
| commit | 9bf82b635712abb148a6ce12e0518ade3a6e6f0a (patch) | |
| tree | 1c42be8e21c92b8a07f7de6c4bf302b6dd054830 | |
| parent | e40d5f29ed0e84348e1fec5d461a8727e7e5a4e0 (diff) | |
| download | puppet-9bf82b635712abb148a6ce12e0518ade3a6e6f0a.tar.gz puppet-9bf82b635712abb148a6ce12e0518ade3a6e6f0a.tar.xz puppet-9bf82b635712abb148a6ce12e0518ade3a6e6f0a.zip | |
adding package source, initially including only files as a source
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@106 980ebf18-57e1-0310-9a29-db15c13687c0
| -rw-r--r-- | lib/blink/objects/package.rb | 44 | ||||
| -rw-r--r-- | test/tc_package.rb | 8 |
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/blink/objects/package.rb b/lib/blink/objects/package.rb index f35368022..faf8905af 100644 --- a/lib/blink/objects/package.rb +++ b/lib/blink/objects/package.rb @@ -193,5 +193,49 @@ module Blink end } } + + # this is how we retrieve packages + class PackageSource + attr_accessor :uri + attr_writer :retrieve + + @@sources = Hash.new(false) + + def PackageSource.get(file) + type = file.sub(%r{:.+},'') + source = nil + if source = @@sources[type] + return source.retrieve(file) + else + raise "Unknown package source: %s" % type + end + end + + def initialize(name) + if block_given? + yield self + end + + @@sources[name] = self + end + + def retrieve(path) + @retrieve.call(path) + end + + end + + PackageSource.new("file") { |obj| + obj.retrieve = proc { |path| + # this might not work for windows... + file = path.sub(%r{^file://},'') + + if FileTest.exists?(file) + return file + else + raise "File %s does not exist" % file + end + } + } end # Blink::Objects end diff --git a/test/tc_package.rb b/test/tc_package.rb index ac9973e35..e9a8bb30e 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -25,3 +25,11 @@ class TestPackagingType < Test::Unit::TestCase end end +class TestPackageSource < Test::Unit::TestCase + def test_filesource + assert_equal( + "/tmp/fakepackage", + Blink::Objects::PackageSource.get("file:///tmp/fakepackage") + ) + end +end |
