From 1bbe67682e798cc918cb917d28249f5ad5eb51fc Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Sat, 29 Aug 2015 17:14:17 -0700 Subject: [PATCH] start migrating file resource Signed-off-by: Dominik Richter --- lib/resources/file.rb | 110 +++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/lib/resources/file.rb b/lib/resources/file.rb index 6ef925885..ae131b9d0 100644 --- a/lib/resources/file.rb +++ b/lib/resources/file.rb @@ -4,66 +4,68 @@ require 'digest' -class File < Vulcano.resource(1) - name 'file' +module Vulcano::Resources + class File < Vulcano.resource(1) + name 'file' - def initialize(path) - @path = path - @file = @vulcano.file(@path) - end - - %w{ - type exists? file? block_device? character_device? socket? - directory? symlink? pipe? - mode owner group link content mtime ctime size selinux_label - readable? writable? executable? mounted? immutable? - }.each do |name| - define_method name.to_sym do |*args| - @file.method(name.to_sym).call(*args) + def initialize(path) + @path = path + @file = @vulcano.file(@path) end - end - def contain(pattern, from, to) - raise ' not yet implemented ' - end - - def mode?(mode) - @file.mode == mode - end - - def owned_by?(owner) - @file.owner == owner - end - - def grouped_into?(group) - @file.group == group - end - - def linked_to?(dst) - @file.linkk == dst - end - - def md5sum - if @file.respond_to?(:md5sum) - @file.md5sum - else - res = Digest::MD5.new - res.update(@file.content) - res.hexdigest + %w{ + type exists? file? block_device? character_device? socket? + directory? symlink? pipe? + mode owner group link content mtime ctime size selinux_label + readable? writable? executable? mounted? immutable? + }.each do |name| + define_method name.to_sym do |*args| + @file.method(name.to_sym).call(*args) + end end - end - def sha256sum - if @file.respond_to?(:sha256sum) - @file.sha256sum - else - res = Digest::SHA256.new - res.update(@file.content) - res.hexdigest + def contain(pattern, from, to) + raise ' not yet implemented ' end - end - def to_s - 'Path "#{@path}"' + def mode?(mode) + @file.mode == mode + end + + def owned_by?(owner) + @file.owner == owner + end + + def grouped_into?(group) + @file.group == group + end + + def linked_to?(dst) + @file.linkk == dst + end + + def md5sum + if @file.respond_to?(:md5sum) + @file.md5sum + else + res = Digest::MD5.new + res.update(@file.content) + res.hexdigest + end + end + + def sha256sum + if @file.respond_to?(:sha256sum) + @file.sha256sum + else + res = Digest::SHA256.new + res.update(@file.content) + res.hexdigest + end + end + + def to_s + 'Path "#{@path}"' + end end end