Class: Autorespawn::TrackedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/autorespawn/tracked_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, mtime: nil, size: nil) ⇒ TrackedFile

Returns a new instance of TrackedFile.



5
6
7
8
9
10
# File 'lib/autorespawn/tracked_file.rb', line 5

def initialize(path, mtime: nil, size: nil)
    @path  = path
    @mtime = mtime
    @size  = size
    @slaves = Array.new
end

Instance Attribute Details

#mtimeObject (readonly)

Returns the value of attribute mtime.



3
4
5
# File 'lib/autorespawn/tracked_file.rb', line 3

def mtime
  @mtime
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/autorespawn/tracked_file.rb', line 3

def path
  @path
end

#sizeObject (readonly)

Returns the value of attribute size.



3
4
5
# File 'lib/autorespawn/tracked_file.rb', line 3

def size
  @size
end

#slavesObject (readonly)

Returns the value of attribute slaves.



3
4
5
# File 'lib/autorespawn/tracked_file.rb', line 3

def slaves
  @slaves
end

Instance Method Details

#updateObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/autorespawn/tracked_file.rb', line 12

def update
    return true if !path.exist?
    return true if !mtime

    stat = path.stat
    if stat.mtime != mtime || stat.size != size
        @mtime = stat.mtime
        @size  = stat.size
        true
    end
end