require 'fileutils' module RCM class File attr_accessor :path, :owner, :group, :mode, :state, :src_path, :changed PRESENT = 'present'.freeze ABSENT = 'absent'.freeze def ==(other) return false unless other.is_a?(RCM::File) # Paths are same and status is absent for both return true if @state == ABSENT && other.state == ABSENT && @path == other.path # Return false if any of the attributes don't match return false unless @owner == other.owner && @group == other.group && @mode == other.mode && @state == other.state && @path == other.path # Check contents of file. At this point, path will be same for the 2 objects. unless @src_path.empty? return ::FileUtils.compare_file(@path, @src_path) end unless other.src_path.empty? return ::FileUtils.compare_file(@path, other.src_path) end end def initialize(path, owner, group, mode, src_path, state) @path = path @owner = owner @group = group @mode = mode @src_path = src_path @state = state @changed = false end def to_s "Path = #{@path}\n" + "Owner = #{@owner}\n" + "Group = #{@group}\n" + "Mode = #{@mode}\n" + "Source Path = #{src_path}\n" + "Changed = #{@changed}" end end end