Class: S3diff::Comparator

Inherits:
Object
  • Object
show all
Defined in:
lib/s3diff/comparator.rb

Instance Method Summary collapse

Constructor Details

#initialize(file1, file2, s3_options = {}) ⇒ Comparator

Returns a new instance of Comparator.



5
6
7
8
9
# 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

Instance Method Details

#both_exist?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
# 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

#diffObject



27
28
29
# File 'lib/s3diff/comparator.rb', line 27

def diff
  @diff ||= Diffy::Diff.new(@file1.path, @file2.path, source: "files")
end

#same?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/s3diff/comparator.rb', line 23

def same?
  same_etag? || diff.to_s.empty?
end

#same_etag?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/s3diff/comparator.rb', line 19

def same_etag?
  both_exist? && @file1.etag == @file2.etag
end