class S3diff::Comparator

Public Class Methods

new(file1, file2, s3_options = {}) click to toggle source
# File lib/s3diff/comparator.rb, line 5
def initialize(file1, file2, s3_options = {})
  @s3_options = s3_options
  @file1 = file_object(file1)
  @file2 = file_object(file2)
end

Public Instance Methods

both_exist?() click to toggle source
# File lib/s3diff/comparator.rb, line 11
def both_exist?
  @both_exist ||= begin
    puts "#{@file1.original_path} is not exist." unless @file1.exist?
    puts "#{@file2.original_path} is not exist." unless @file2.exist?
    @file1.exist? && @file2.exist?
  end
end
diff() click to toggle source
# File lib/s3diff/comparator.rb, line 27
def diff
  @diff ||= Diffy::Diff.new(@file1.path, @file2.path, source: "files")
end
same?() click to toggle source
# File lib/s3diff/comparator.rb, line 23
def same?
  same_etag? || diff.to_s.empty?
end
same_etag?() click to toggle source
# File lib/s3diff/comparator.rb, line 19
def same_etag?
  both_exist? && @file1.etag == @file2.etag
end

Private Instance Methods

file_object(file) click to toggle source
# File lib/s3diff/comparator.rb, line 33
def file_object(file)
  uri = URI.parse(file)
  case uri.scheme
  when "s3" then S3File.new(file, s3_client)
  else LocalFile.new(file)
  end
end
s3_client() click to toggle source
# File lib/s3diff/comparator.rb, line 41
def s3_client
  @s3c ||= S3Client.new(@s3_options)
end