Class: Puppet::FileServing::Base Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/file_serving/base.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

API:

  • private

Direct Known Subclasses

Content, Metadata

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, links: nil, relative_path: nil, source: nil) ⇒ Base

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Base.

API:

  • private



36
37
38
39
40
41
42
43
# File 'lib/puppet/file_serving/base.rb', line 36

def initialize(path, links: nil, relative_path: nil, source: nil)
  self.path = path
  @links = :manage

  self.links = links if links
  self.relative_path = relative_path if relative_path
  self.source = source if source
end

Instance Attribute Details

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determine how we deal with links.

API:

  • private



46
47
48
# File 'lib/puppet/file_serving/base.rb', line 46

def links
  @links
end

#pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set our base path.

API:

  • private



56
57
58
# File 'lib/puppet/file_serving/base.rb', line 56

def path
  @path
end

#relative_pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set a relative path; this is used for recursion, and sets the file's path relative to the initial recursion point.

API:

  • private



64
65
66
# File 'lib/puppet/file_serving/base.rb', line 64

def relative_path
  @relative_path
end

#sourceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This is for external consumers to store the source that was used to retrieve the metadata.

API:

  • private



10
11
12
# File 'lib/puppet/file_serving/base.rb', line 10

def source
  @source
end

Class Method Details

.absolute?(path) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

API:

  • private



84
85
86
# File 'lib/puppet/file_serving/base.rb', line 84

def self.absolute?(path)
  Puppet::Util.absolute_path?(path, :posix) || (Puppet::Util::Platform.windows? && Puppet::Util.absolute_path?(path, :windows))
end

Instance Method Details

#exist?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Does our file exist?

Returns:

API:

  • private



13
14
15
16
17
18
# File 'lib/puppet/file_serving/base.rb', line 13

def exist?
    stat
    return true
rescue
    return false
end

#full_pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the full path to our file. Fails if there's no path set.

API:

  • private



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puppet/file_serving/base.rb', line 21

def full_path
  if relative_path.nil? or relative_path == "" or relative_path == "."
    full_path = path
  else
    full_path = File.join(path, relative_path)
  end

  if Puppet::Util::Platform.windows?
    # Replace multiple slashes as long as they aren't at the beginning of a filename
    full_path.gsub(%r{(./)/+}, '\1')
  else
    full_path.gsub(%r{//+}, '/')
  end
end

#statObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

API:

  • private



71
72
73
74
# File 'lib/puppet/file_serving/base.rb', line 71

def stat
  @stat_method ||= self.links == :manage ? :lstat : :stat
  Puppet::FileSystem.send(@stat_method, full_path)
end

#to_data_hashObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



76
77
78
79
80
81
82
# File 'lib/puppet/file_serving/base.rb', line 76

def to_data_hash
  {
    'path'          => @path,
    'relative_path' => @relative_path,
    'links'         => @links.to_s
  }
end