diff options
author | Rick Bradley <rick@rickbradley.com> | 2007-10-23 07:28:42 -0500 |
---|---|---|
committer | Rick Bradley <rick@rickbradley.com> | 2007-10-23 07:28:42 -0500 |
commit | 7def1eaa0e6e559ed70f260bf7b42d8e84d3740b (patch) | |
tree | 81c91d425f015a634e5fe45e500ca0dec87bc0f6 /lib/puppet/file_serving/file_base.rb | |
parent | b134f0ce465923a6b0b7f2855850e38599f0f176 (diff) | |
parent | de5d91e2036de2934a4eec79d35a714f3ed24b10 (diff) | |
download | puppet-7def1eaa0e6e559ed70f260bf7b42d8e84d3740b.tar.gz puppet-7def1eaa0e6e559ed70f260bf7b42d8e84d3740b.tar.xz puppet-7def1eaa0e6e559ed70f260bf7b42d8e84d3740b.zip |
Merge branch 'master' of git://reductivelabs.com/puppet into routing
Diffstat (limited to 'lib/puppet/file_serving/file_base.rb')
-rw-r--r-- | lib/puppet/file_serving/file_base.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/puppet/file_serving/file_base.rb b/lib/puppet/file_serving/file_base.rb new file mode 100644 index 000000000..b2e9a0656 --- /dev/null +++ b/lib/puppet/file_serving/file_base.rb @@ -0,0 +1,46 @@ +# +# Created by Luke Kanies on 2007-10-22. +# Copyright (c) 2007. All rights reserved. + +require 'puppet/file_serving' + +# The base class for Content and Metadata; provides common +# functionality like the behaviour around links. +class Puppet::FileServing::FileBase + attr_accessor :path, :base_path + + def full_path(base = nil) + base ||= base_path || raise(ArgumentError, "You must set or provide a base path") + + full = File.join(base, self.path) + end + + def initialize(path, options = {}) + raise ArgumentError.new("Files must not be fully qualified") if path =~ /^#{::File::SEPARATOR}/ + + @path = path + @links = :manage + + options.each do |param, value| + begin + send param.to_s + "=", value + rescue NoMethodError + raise ArgumentError, "Invalid option %s for %s" % [param, self.class] + end + end + end + + attr_reader :links + def links=(value) + raise(ArgumentError, ":links can only be set to :manage or :follow") unless [:manage, :follow].include?(value) + @links = value + end + + # Stat our file, using the appropriate link-sensitive method. + def stat(base = nil) + unless defined?(@stat_method) + @stat_method = self.links == :manage ? :lstat : :stat + end + File.send(@stat_method, full_path(base)) + end +end |