blob: d1073f2042bc701a646d848b9baf95e898e175b4 (
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
|
require 'fileutils'
require_relative 'file'
module RCM
# Creates an empty file (touch semantics). Supports the additional
# :updated state which re-touches the file even when it already exists.
class Touch < BaseFile
def is(what) = @is = validate(__method__, what.to_sym, :present, :absent, :purged, :updated)
def evaluate!
return unless super
return evaluate_absent! if %i[absent purged].include?(@is)
return if ::File.file?(@file_path) && @is != :updated
create_parent_directory! if @manage_directory
do? "Touching #{@file_path}" do
FileUtils.touch(@file_path)
end
ensure
permissions!
end
end
class DSL
def touch(file_path = nil, &block)
return :touch if file_path.nil?
return unless @conds_met
t = Touch.new(file_path)
t.instance_eval(&block) if block
self << t
t
end
end
end
|