summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parsedfile.rb
blob: e32a2daef5bedb3f304fdb2546516c0342bc5193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# A simple class that tells us when a file has changed and thus whether we
# should reload it

require 'puppet'

module Puppet
    class ParsedFile
        attr_reader :file

        # Determine whether the file has changed and thus whether it should
        # be reparsed
        def changed?
            tmp = self.stamp
            retval = false
            if tmp != @stamp
                retval = true
                @stamp = tmp
            end
            @statted = Time.now

            return retval
        end

        # Create the file.  Must be passed the file path.
        def initialize(file)
            @file = file
            unless FileTest.exists?(@file)
                raise Puppet::DevError, "Can not use a non-existent file for parsing"
            end
            @stamp = self.stamp
            @statted = Time.now
        end

        def stamp
            File.stat(@file).ctime
        end
    end
end