Class: FSSM::State::File

Inherits:
Object
  • Object
show all
Defined in:
lib/fssm/state/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ File

Returns a new instance of File.


5
6
7
# File 'lib/fssm/state/file.rb', line 5

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path


3
4
5
# File 'lib/fssm/state/file.rb', line 3

def path
  @path
end

Instance Method Details

#refresh(base = nil, skip_callbacks = false) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fssm/state/file.rb', line 9

def refresh(base=nil, skip_callbacks=false)
  base ||= @path.to_pathname
  used_to_exist, @exists = @exists, base.exist?
  # this handles bad symlinks without failing. why handle bad symlinks at
  # all? well, we could still be interested in their creation and deletion.
  old_mtime, @mtime = @mtime, base.symlink? ? Time.at(0) : base.mtime if @exists

  unless skip_callbacks
    @path.delete(@path.to_s) if used_to_exist && !@exists
    @path.create(@path.to_s) if !used_to_exist && @exists
    @path.update(@path.to_s) if used_to_exist && @exists && old_mtime != @mtime
  end
end