Class: Puppet::FileServing::Content

Inherits:
Base show all
Extended by:
Indirector
Defined in:
lib/puppet/file_serving/content.rb

Overview

A class that handles retrieving file contents. It only reads the file when its content is specifically asked for.

Constant Summary

Constants included from Indirector

Indirector::BadNameRegexp

Instance Attribute Summary collapse

Attributes inherited from Base

#links, #path, #relative_path, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Indirector

configure_routes, indirects

Methods inherited from Base

#exist?, #full_path, #initialize, #stat, #to_pson_data_hash

Constructor Details

This class inherits a constructor from Puppet::FileServing::Base

Instance Attribute Details

#contentObject

Read the content of our file in.



33
34
35
36
37
38
39
40
41
# File 'lib/puppet/file_serving/content.rb', line 33

def content
  unless @content
    # This stat can raise an exception, too.
    raise(ArgumentError, "Cannot read the contents of links unless following links") if stat.ftype == "symlink"

    @content = ::File.read(full_path)
  end
  @content
end

Class Method Details

.from_raw(content) ⇒ Object



19
20
21
22
23
# File 'lib/puppet/file_serving/content.rb', line 19

def self.from_raw(content)
  instance = new("/this/is/a/fake/path")
  instance.content = content
  instance
end

.supported_formatsObject



15
16
17
# File 'lib/puppet/file_serving/content.rb', line 15

def self.supported_formats
  [:raw]
end

Instance Method Details

#collectObject

BF: we used to fetch the file content here, but this is counter-productive for puppetmaster streaming of file content. So collect just returns itself



27
28
29
30
# File 'lib/puppet/file_serving/content.rb', line 27

def collect
  return if stat.ftype == "directory"
  self
end

#to_rawObject



43
44
45
# File 'lib/puppet/file_serving/content.rb', line 43

def to_raw
  File.new(full_path, "rb")
end