Module: CmpFS::Compare::Binary::Internal_

Defined in:
lib/cmpfs/compare/binary/internal_.rb

Class Method Summary collapse

Class Method Details

.compare_binary_(lhs, rhs, options) ⇒ Object

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cmpfs/compare/binary/internal_.rb', line 39

def self.compare_binary_ lhs, rhs, options

  lhs_type	=	self.determine_param_type_ lhs
  rhs_type	=	self.determine_param_type_ rhs

  raise ArgumentError, "lhs is of unsupported type '#{lhs.class}'" unless lhs_type
  raise ArgumentError, "rhs is of unsupported type '#{rhs.class}'" unless rhs_type

  if lhs_type == rhs_type

    case lhs_type
    when :io

      return self.compare_binary_streams_ lhs, rhs, options
    when :path

      return self.compare_binary_files_ lhs, rhs, options
    end
  else

    case lhs_type
    when :io

      if :path == rhs_type

      	File.open(rhs, 'rb') do |rhs_f|

      		return self.compare_binary_streams_ lhs, rhs_f, options
      	end
      end
    when :path

      if :path == lhs_type

      	File.open(lhs, 'rb') do |lhs_f|

      		return self.compare_binary_streams_ lhs_f, rhs, options
      	end
      end
    end
  end

  warn "#{__method__}: incompatible types (#{lhs.type}, #{rhs.type})"

  nil
end

.compare_binary_files_(lhs_path, rhs_path, options) ⇒ Object



29
30
31
32
# File 'lib/cmpfs/compare/binary/internal_.rb', line 29

def self.compare_binary_files_ lhs_path, rhs_path, options

  FileUtils.compare_file lhs_path, rhs_path
end

.compare_binary_streams_(lhs_stm, rhs_stm, options) ⇒ Object



34
35
36
37
# File 'lib/cmpfs/compare/binary/internal_.rb', line 34

def self.compare_binary_streams_ lhs_stm, rhs_stm, options

  FileUtils.compare_stream lhs_stm, rhs_stm
end

.determine_param_type_(p) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cmpfs/compare/binary/internal_.rb', line 12

def self.determine_param_type_ p

  case p
  when ::IO, ::StringIO

    return :io
  when ::String

    return :path
  else

    return :path if p.respond_to?(:to_str)

    return nil
  end
end