class Puppet::FileServing::Base
The base class for Content and Metadata; provides common functionality like the behaviour around links.
Attributes
links[R]
Determine how we deal with links.
path[R]
Set our base path.
relative_path[R]
Set a relative path; this is used for recursion, and sets the file's path relative to the initial recursion point.
source[RW]
This is for external consumers to store the source that was used to retrieve the metadata.
Public Class Methods
absolute?(path)
click to toggle source
# File lib/puppet/file_serving/base.rb 83 def self.absolute?(path) 84 Puppet::Util.absolute_path?(path, :posix) || (Puppet::Util::Platform.windows? && Puppet::Util.absolute_path?(path, :windows)) 85 end
new(path, links: nil, relative_path: nil, source: nil)
click to toggle source
# File lib/puppet/file_serving/base.rb 35 def initialize(path, links: nil, relative_path: nil, source: nil) 36 self.path = path 37 @links = :manage 38 39 self.links = links if links 40 self.relative_path = relative_path if relative_path 41 self.source = source if source 42 end
Public Instance Methods
exist?()
click to toggle source
Does our file exist?
# File lib/puppet/file_serving/base.rb 12 def exist? 13 stat 14 return true 15 rescue 16 return false 17 end
full_path()
click to toggle source
Return the full path to our file. Fails if there's no path set.
# File lib/puppet/file_serving/base.rb 20 def full_path 21 if relative_path.nil? or relative_path == "" or relative_path == "." 22 full_path = path 23 else 24 full_path = File.join(path, relative_path) 25 end 26 27 if Puppet::Util::Platform.windows? 28 # Replace multiple slashes as long as they aren't at the beginning of a filename 29 full_path.gsub(%r{(./)/+}, '\1') 30 else 31 full_path.gsub(%r{//+}, '/') 32 end 33 end
links=(value)
click to toggle source
# File lib/puppet/file_serving/base.rb 46 def links=(value) 47 value = value.to_sym 48 value = :manage if value == :ignore 49 #TRANSLATORS ':link', ':manage', ':follow' should not be translated 50 raise(ArgumentError, _(":links can only be set to :manage or :follow")) unless [:manage, :follow].include?(value) 51 @links = value 52 end
path=(path)
click to toggle source
# File lib/puppet/file_serving/base.rb 56 def path=(path) 57 raise ArgumentError.new(_("Paths must be fully qualified")) unless Puppet::FileServing::Base.absolute?(path) 58 @path = path 59 end
relative_path=(path)
click to toggle source
# File lib/puppet/file_serving/base.rb 64 def relative_path=(path) 65 raise ArgumentError.new(_("Relative paths must not be fully qualified")) if Puppet::FileServing::Base.absolute?(path) 66 @relative_path = path 67 end
stat()
click to toggle source
Stat our file, using the appropriate link-sensitive method.
# File lib/puppet/file_serving/base.rb 70 def stat 71 @stat_method ||= self.links == :manage ? :lstat : :stat 72 Puppet::FileSystem.send(@stat_method, full_path) 73 end
to_data_hash()
click to toggle source
# File lib/puppet/file_serving/base.rb 75 def to_data_hash 76 { 77 'path' => @path, 78 'relative_path' => @relative_path, 79 'links' => @links.to_s 80 } 81 end