start migrating file resource

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-08-29 17:14:17 -07:00
parent 50a5803427
commit 1bbe67682e

View file

@ -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