class FileServing::Base

The base class for Content and Metadata; provides common functionality like the behaviour around links.

Attributes

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, line 81
def self.absolute?(path)
  Puppet::Util.absolute_path?(path, :posix) or (Puppet.features.microsoft_windows? and Puppet::Util.absolute_path?(path, :windows))
end
new(path, options = {}) click to toggle source
# File lib/puppet/file_serving/base.rb, line 31
def initialize(path, options = {})
  self.path = path
  @links = :manage
  set_options(options)
end

Public Instance Methods

exist?() click to toggle source

Does our file exist?

# File lib/puppet/file_serving/base.rb, line 15
def exist?
    stat
    return true
rescue => detail
    return false
end
full_path(dummy_argument=:work_arround_for_ruby_GC_bug) 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, line 23
def full_path(dummy_argument=:work_arround_for_ruby_GC_bug)
  (if relative_path.nil? or relative_path == "" or relative_path == "."
     path
   else
     File.join(path, relative_path)
   end).gsub(%r{//+}, "/")
end
path=(path) click to toggle source
# File lib/puppet/file_serving/base.rb, line 48
def path=(path)
  raise ArgumentError.new("Paths must be fully qualified") unless Puppet::FileServing::Base.absolute?(path)
  @path = path
end
relative_path=(path) click to toggle source
# File lib/puppet/file_serving/base.rb, line 56
def relative_path=(path)
  raise ArgumentError.new("Relative paths must not be fully qualified") if Puppet::FileServing::Base.absolute?(path)
  @relative_path = path
end
stat() click to toggle source

Stat our file, using the appropriate link-sensitive method.

# File lib/puppet/file_serving/base.rb, line 62
def stat
  @stat_method ||= self.links == :manage ? :lstat : :stat
  File.send(@stat_method, full_path)
end
to_pson_data_hash() click to toggle source
# File lib/puppet/file_serving/base.rb, line 67
def to_pson_data_hash
  {
    # No 'document_type' since we don't send these bare
    'data'       => {
      'path'          => @path,
      'relative_path' => @relative_path,
      'links'         => @links
      },
    'metadata' => {
      'api_version' => 1
      }
  }
end