Class: Puppet::Util::LoadedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/puppet/util/loadedfile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ LoadedFile

Create the file. Must be passed the file path.



35
36
37
38
39
40
# File 'lib/vendor/puppet/util/loadedfile.rb', line 35

def initialize(file)
  @file = file
  @statted = 0
  @stamp = nil
  @tstamp = stamp
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



9
10
11
# File 'lib/vendor/puppet/util/loadedfile.rb', line 9

def file
  @file
end

#stattedObject (readonly)

Returns the value of attribute statted.



9
10
11
# File 'lib/vendor/puppet/util/loadedfile.rb', line 9

def statted
  @statted
end

#tstamp=(value) ⇒ Object (writeonly)

Provide a hook for setting the timestamp during testing, so we don’t have to depend on the granularity of the filesystem.



13
14
15
# File 'lib/vendor/puppet/util/loadedfile.rb', line 13

def tstamp=(value)
  @tstamp = value
end

Instance Method Details

#changed?Boolean

Determine whether the file has changed and thus whether it should be reparsed.

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vendor/puppet/util/loadedfile.rb', line 17

def changed?
  # Allow the timeout to be disabled entirely.
  return true if Puppet[:filetimeout] < 0
  tmp = stamp

  # We use a different internal variable than the stamp method
  # because it doesn't keep historical state and we do -- that is,
  # we will always be comparing two timestamps, whereas
  # stamp just always wants the latest one.
  if tmp == @tstamp
    return false
  else
    @tstamp = tmp
    return @tstamp
  end
end

#stampObject

Retrieve the filestamp, but only refresh it if we’re beyond our filetimeout



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vendor/puppet/util/loadedfile.rb', line 44

def stamp
  if @stamp.nil? or (Time.now.to_i - @statted >= Puppet[:filetimeout])
    @statted = Time.now.to_i
    begin
      @stamp = File.stat(@file).ctime
    rescue Errno::ENOENT, Errno::ENOTDIR
      @stamp = Time.now
    end
  end
  @stamp
end

#to_sObject



56
57
58
# File 'lib/vendor/puppet/util/loadedfile.rb', line 56

def to_s
  @file
end