diff options
| author | Paul Buetow <paul@buetow.org> | 2025-02-25 22:42:45 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-02-25 22:42:45 +0200 |
| commit | d7254b1f4ab4ef482ac9adc1dbb0b896b1c63ebb (patch) | |
| tree | f2292bb1a1fef690a725f88d70685e4efacfd27f /lib/dslkeywords | |
| parent | 24a0c5406251db11cf12bec4f0429446080839a8 (diff) | |
add touch file
Diffstat (limited to 'lib/dslkeywords')
| -rw-r--r-- | lib/dslkeywords/file.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/dslkeywords/file.rb b/lib/dslkeywords/file.rb index 50728cb..39e0499 100644 --- a/lib/dslkeywords/file.rb +++ b/lib/dslkeywords/file.rb @@ -190,6 +190,23 @@ module RCM end end + # Emtpy file + 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) + + create_parent_directory! if @manage_directory + dry? "Touching #{@file_path}" do + return if @is != :updated && ::File.file?(@file_path) + + FileUtils.touch(@file_path) + end + end + end + class Directory < BaseFile def evaluate! return unless super @@ -249,6 +266,16 @@ module RCM s end + 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 + def directory(file_path = nil, &block) return :directory if file_path.nil? return unless @conds_met |
