cmpfs-ruby 0.2.0 → 0.2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/LICENSE +17 -16
- data/README.md +20 -9
- data/lib/cmpfs/compare/api_1_9.rb +121 -120
- data/lib/cmpfs/compare/api_2.rb +109 -108
- data/lib/cmpfs/compare/binary/internal_.rb +50 -52
- data/lib/cmpfs/compare/text/internal_.rb +89 -92
- data/lib/cmpfs/compare.rb +25 -23
- data/lib/cmpfs/version.rb +20 -19
- data/lib/cmpfs.rb +16 -12
- data/test/unit/compare/tc_compare_binary.rb +52 -51
- data/test/unit/tc_compare_binary.rb +53 -54
- data/test/unit/tc_compare_text.rb +85 -31
- data/test/unit/tc_version.rb +19 -16
- metadata +22 -17
@@ -1,89 +1,87 @@
|
|
1
1
|
|
2
|
-
#require 'xqsr3'
|
3
|
-
|
4
2
|
require 'fileutils'
|
5
3
|
require 'stringio'
|
6
4
|
|
5
|
+
|
7
6
|
module CmpFS
|
8
7
|
module Compare
|
9
8
|
module Binary
|
10
9
|
|
11
10
|
module Internal_
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
case p
|
16
|
-
when ::IO, ::StringIO
|
12
|
+
def self.determine_param_type_ p
|
17
13
|
|
18
|
-
|
19
|
-
|
14
|
+
case p
|
15
|
+
when ::IO, ::StringIO
|
20
16
|
|
21
|
-
|
22
|
-
|
17
|
+
return :io
|
18
|
+
when ::String
|
23
19
|
|
24
|
-
|
20
|
+
return :path
|
21
|
+
else
|
25
22
|
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
23
|
+
return :path if p.respond_to?(:to_str)
|
29
24
|
|
30
|
-
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
end
|
31
28
|
|
32
|
-
|
33
|
-
end
|
29
|
+
def self.compare_binary_files_ lhs_path, rhs_path, options
|
34
30
|
|
35
|
-
|
31
|
+
FileUtils.compare_file lhs_path, rhs_path
|
32
|
+
end
|
36
33
|
|
37
|
-
|
38
|
-
end
|
34
|
+
def self.compare_binary_streams_ lhs_stm, rhs_stm, options
|
39
35
|
|
40
|
-
|
36
|
+
FileUtils.compare_stream lhs_stm, rhs_stm
|
37
|
+
end
|
41
38
|
|
39
|
+
def self.compare_binary_ lhs, rhs, options
|
42
40
|
|
43
|
-
|
44
|
-
|
41
|
+
lhs_type = self.determine_param_type_ lhs
|
42
|
+
rhs_type = self.determine_param_type_ rhs
|
45
43
|
|
46
|
-
|
47
|
-
|
44
|
+
raise ArgumentError, "lhs is of unsupported type '#{lhs.class}'" unless lhs_type
|
45
|
+
raise ArgumentError, "rhs is of unsupported type '#{rhs.class}'" unless rhs_type
|
48
46
|
|
49
|
-
|
47
|
+
if lhs_type == rhs_type
|
50
48
|
|
51
|
-
|
52
|
-
|
49
|
+
case lhs_type
|
50
|
+
when :io
|
53
51
|
|
54
|
-
|
55
|
-
|
52
|
+
return self.compare_binary_streams_ lhs, rhs, options
|
53
|
+
when :path
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
return self.compare_binary_files_ lhs, rhs, options
|
56
|
+
end
|
57
|
+
else
|
60
58
|
|
61
|
-
|
62
|
-
|
59
|
+
case lhs_type
|
60
|
+
when :io
|
63
61
|
|
64
|
-
|
62
|
+
if :path == rhs_type
|
65
63
|
|
66
|
-
|
64
|
+
File.open(rhs, 'rb') do |rhs_f|
|
67
65
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
66
|
+
return self.compare_binary_streams_ lhs, rhs_f, options
|
67
|
+
end
|
68
|
+
end
|
69
|
+
when :path
|
72
70
|
|
73
|
-
|
71
|
+
if :path == lhs_type
|
74
72
|
|
75
|
-
|
73
|
+
File.open(lhs, 'rb') do |lhs_f|
|
76
74
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
75
|
+
return self.compare_binary_streams_ lhs_f, rhs, options
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
82
80
|
|
83
|
-
|
81
|
+
warn "#{__method__}: incompatible types (#{lhs.type}, #{rhs.type})"
|
84
82
|
|
85
|
-
|
86
|
-
|
83
|
+
nil
|
84
|
+
end
|
87
85
|
|
88
86
|
end # module Internal_
|
89
87
|
|
@@ -91,6 +89,6 @@ end # module Binary
|
|
91
89
|
end # module Compare
|
92
90
|
end # module CmpFS
|
93
91
|
|
94
|
-
# ############################## end of file ############################# #
|
95
92
|
|
93
|
+
# ############################## end of file ############################# #
|
96
94
|
|
@@ -1,159 +1,156 @@
|
|
1
1
|
|
2
|
-
#require 'xqsr3'
|
3
|
-
|
4
2
|
require 'fileutils'
|
5
3
|
require 'stringio'
|
6
4
|
|
5
|
+
|
7
6
|
module CmpFS
|
8
7
|
module Compare
|
9
8
|
module Text
|
10
9
|
|
11
10
|
module Internal_
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
case p
|
16
|
-
when ::IO, ::StringIO
|
12
|
+
def self.determine_param_type_ p
|
17
13
|
|
18
|
-
|
19
|
-
|
14
|
+
case p
|
15
|
+
when ::IO, ::StringIO
|
20
16
|
|
21
|
-
|
22
|
-
|
17
|
+
return :io
|
18
|
+
when ::String
|
23
19
|
|
24
|
-
|
20
|
+
return :path
|
21
|
+
else
|
25
22
|
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
23
|
+
return :path if p.respond_to?(:to_str)
|
29
24
|
|
30
|
-
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
end
|
31
28
|
|
32
|
-
|
33
|
-
skipping_blanks = options[:skip_blank_lines]
|
29
|
+
def self.next_line_or_nil_ en, options
|
34
30
|
|
35
|
-
|
31
|
+
skipping_blanks = options[:skip_blank_lines]
|
32
|
+
trimming_lines = options[:trim_lines]
|
36
33
|
|
37
|
-
|
34
|
+
num_read = 0
|
38
35
|
|
39
|
-
|
36
|
+
begin
|
40
37
|
|
41
|
-
|
38
|
+
loop do
|
42
39
|
|
43
|
-
|
40
|
+
line = en.next
|
44
41
|
|
45
|
-
|
42
|
+
num_read += 1
|
46
43
|
|
47
|
-
|
44
|
+
line = line.strip if trimming_lines
|
48
45
|
|
49
|
-
|
50
|
-
end
|
46
|
+
if line.empty? && skipping_blanks
|
51
47
|
|
52
|
-
|
53
|
-
|
54
|
-
rescue StopIteration
|
48
|
+
next
|
49
|
+
end
|
55
50
|
|
56
|
-
|
51
|
+
return [ line, num_read ]
|
52
|
+
end
|
53
|
+
rescue StopIteration
|
57
54
|
|
58
|
-
|
59
|
-
end
|
55
|
+
end
|
60
56
|
|
61
|
-
|
57
|
+
return [ nil, num_read ]
|
58
|
+
end
|
62
59
|
|
63
|
-
|
60
|
+
def self.compare_text_files_ lhs_path, rhs_path, options
|
64
61
|
|
65
|
-
|
62
|
+
File.open(lhs_path, 'r') do |lhs_stm|
|
66
63
|
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
64
|
+
File.open(rhs_path, 'r') do |rhs_stm|
|
71
65
|
|
72
|
-
|
66
|
+
self.compare_text_streams_ lhs_stm, rhs_stm, options.merge(no_rewind: true)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
73
70
|
|
74
|
-
|
75
|
-
rhs_en = rhs_stm.each_line
|
71
|
+
def self.compare_text_streams_ lhs_stm, rhs_stm, options
|
76
72
|
|
77
|
-
|
73
|
+
lhs_en = lhs_stm.each_line
|
74
|
+
rhs_en = rhs_stm.each_line
|
78
75
|
|
79
|
-
|
80
|
-
rhs_en.rewind if rhs_stm.respond_to?(:rewind)
|
81
|
-
end
|
76
|
+
unless options[:no_rewind]
|
82
77
|
|
83
|
-
|
84
|
-
|
78
|
+
lhs_en.rewind if lhs_stm.respond_to?(:rewind)
|
79
|
+
rhs_en.rewind if rhs_stm.respond_to?(:rewind)
|
80
|
+
end
|
85
81
|
|
86
|
-
|
82
|
+
lhs_ix = 0
|
83
|
+
rhs_ix = 0
|
87
84
|
|
88
|
-
|
89
|
-
rhs_ln, rhs_nr = self.next_line_or_nil_ rhs_en, options
|
85
|
+
loop do
|
90
86
|
|
91
|
-
|
87
|
+
lhs_ln, lhs_nr = self.next_line_or_nil_ lhs_en, options
|
88
|
+
rhs_ln, rhs_nr = self.next_line_or_nil_ rhs_en, options
|
92
89
|
|
93
|
-
|
94
|
-
else
|
90
|
+
if lhs_ln != rhs_ln
|
95
91
|
|
96
|
-
|
97
|
-
|
98
|
-
end
|
92
|
+
return false
|
93
|
+
else
|
99
94
|
|
100
|
-
|
101
|
-
|
95
|
+
return true if lhs_ln.nil?
|
96
|
+
end
|
97
|
+
end
|
102
98
|
|
103
|
-
|
99
|
+
return true
|
100
|
+
end
|
104
101
|
|
105
|
-
|
106
|
-
rhs_type = self.determine_param_type_ rhs
|
102
|
+
def self.compare_text_ lhs, rhs, options
|
107
103
|
|
108
|
-
|
109
|
-
|
104
|
+
lhs_type = self.determine_param_type_ lhs
|
105
|
+
rhs_type = self.determine_param_type_ rhs
|
110
106
|
|
111
|
-
|
107
|
+
raise ArgumentError, "lhs is of unsupported type '#{lhs.class}'" unless lhs_type
|
108
|
+
raise ArgumentError, "rhs is of unsupported type '#{rhs.class}'" unless rhs_type
|
112
109
|
|
113
|
-
|
114
|
-
when :io
|
110
|
+
if lhs_type == rhs_type
|
115
111
|
|
116
|
-
|
117
|
-
|
112
|
+
case lhs_type
|
113
|
+
when :io
|
118
114
|
|
119
|
-
|
120
|
-
|
121
|
-
else
|
115
|
+
return self.compare_text_streams_ lhs, rhs, options
|
116
|
+
when :path
|
122
117
|
|
123
|
-
|
124
|
-
|
118
|
+
return self.compare_text_files_ lhs, rhs, options
|
119
|
+
end
|
120
|
+
else
|
125
121
|
|
126
|
-
|
122
|
+
case lhs_type
|
123
|
+
when :io
|
127
124
|
|
128
|
-
|
125
|
+
if :path == rhs_type
|
129
126
|
|
130
|
-
|
131
|
-
end
|
132
|
-
end
|
133
|
-
when :path
|
127
|
+
File.open(rhs, 'r') do |rhs_f|
|
134
128
|
|
135
|
-
|
129
|
+
return self.compare_text_streams_ lhs, rhs_f, options
|
130
|
+
end
|
131
|
+
end
|
132
|
+
when :path
|
136
133
|
|
137
|
-
|
134
|
+
if :path == lhs_type
|
138
135
|
|
139
|
-
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
136
|
+
File.open(lhs, 'r') do |lhs_f|
|
144
137
|
|
145
|
-
|
138
|
+
return self.compare_text_streams_ lhs_f, rhs, options
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
146
143
|
|
147
|
-
|
148
|
-
end
|
144
|
+
warn "#{__method__}: incompatible types (#{lhs.type}, #{rhs.type})"
|
149
145
|
|
146
|
+
nil
|
147
|
+
end
|
150
148
|
end # module Internal_
|
151
149
|
|
152
150
|
end # module Text
|
153
151
|
end # module Compare
|
154
152
|
end # module CmpFS
|
155
153
|
|
156
|
-
# ############################## end of file ############################# #
|
157
|
-
|
158
154
|
|
155
|
+
# ############################## end of file ############################# #
|
159
156
|
|
data/lib/cmpfs/compare.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: cmpfs/version.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
5
|
+
# Purpose: Version for cmpfs.Ruby library
|
6
6
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
7
|
+
# Created: 1st March 2019
|
8
|
+
# Updated: 1st April 2024
|
9
9
|
#
|
10
|
-
# Home:
|
10
|
+
# Home: http://github.com/synesissoftware/cmpfs.Ruby
|
11
11
|
#
|
12
|
-
# Author:
|
12
|
+
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
14
15
|
# Copyright (c) 2019, Matthew Wilson and Synesis Software
|
15
16
|
# All rights reserved.
|
16
17
|
#
|
@@ -46,12 +47,13 @@
|
|
46
47
|
|
47
48
|
if RUBY_VERSION >= '2'
|
48
49
|
|
49
|
-
|
50
|
+
require 'cmpfs/compare/api_2'
|
50
51
|
else
|
51
52
|
|
52
|
-
|
53
|
+
require 'cmpfs/compare/api_1_9'
|
53
54
|
end
|
54
55
|
|
56
|
+
|
55
57
|
=begin
|
56
58
|
=end
|
57
59
|
|
@@ -73,32 +75,32 @@ module CmpFS
|
|
73
75
|
#
|
74
76
|
module Compare
|
75
77
|
|
76
|
-
|
78
|
+
def self.extended receiver
|
77
79
|
|
78
|
-
|
80
|
+
receiver.class_eval do
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
+
extend CmpFS_Compare_Methods
|
83
|
+
end
|
82
84
|
|
83
|
-
|
84
|
-
|
85
|
+
$stderr.puts "#{receiver} extended by #{CmpFS_Compare_Methods}" if $DEBUG
|
86
|
+
end
|
85
87
|
|
86
|
-
|
88
|
+
def self.included receiver
|
87
89
|
|
88
|
-
|
90
|
+
receiver.class_eval do
|
89
91
|
|
90
|
-
|
91
|
-
|
92
|
+
include CmpFS_Compare_Methods
|
93
|
+
end
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
+
$stderr.puts "#{receiver} included #{CmpFS_Compare_Methods}" if $DEBUG
|
96
|
+
end
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
+
extend CmpFS_Compare_Methods
|
99
|
+
include CmpFS_Compare_Methods
|
98
100
|
|
99
101
|
end # module Compare
|
100
102
|
end # module CmpFS
|
101
103
|
|
102
|
-
# ############################## end of file ############################# #
|
103
104
|
|
105
|
+
# ############################## end of file ############################# #
|
104
106
|
|
data/lib/cmpfs/version.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: cmpfs/version.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
5
|
+
# Purpose: Version for cmpfs.Ruby library
|
6
6
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
7
|
+
# Created: 1st March 2019
|
8
|
+
# Updated: 1st April 2024
|
9
9
|
#
|
10
|
-
# Home:
|
10
|
+
# Home: http://github.com/synesissoftware/cmpfs.Ruby
|
11
11
|
#
|
12
|
-
# Author:
|
12
|
+
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
14
15
|
# Copyright (c) 2019, Matthew Wilson and Synesis Software
|
15
16
|
# All rights reserved.
|
16
17
|
#
|
@@ -49,23 +50,23 @@
|
|
49
50
|
|
50
51
|
module CmpFS
|
51
52
|
|
52
|
-
|
53
|
-
|
53
|
+
# Current version of the cmpfs.Ruby library
|
54
|
+
VERSION = '0.2.1.1'
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
56
|
+
private
|
57
|
+
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
58
|
+
public
|
59
|
+
# Major version of the cmpfs.Ruby library
|
60
|
+
VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
|
61
|
+
# Minor version of the cmpfs.Ruby library
|
62
|
+
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
63
|
+
# Revision version of the cmpfs.Ruby library
|
64
|
+
VERSION_PATCH = VERSION_PARTS_[2] # :nodoc:
|
64
65
|
|
65
|
-
|
66
|
+
VERSION_REVISION = VERSION_PATCH # :nodoc:
|
66
67
|
|
67
68
|
end # module CmpFS
|
68
69
|
|
69
|
-
# ############################## end of file ############################# #
|
70
70
|
|
71
|
+
# ############################## end of file ############################# #
|
71
72
|
|
data/lib/cmpfs.rb
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
14
15
|
# Copyright (c) 2019, Matthew Wilson and Synesis Software
|
15
16
|
# All rights reserved.
|
16
17
|
#
|
@@ -53,25 +54,28 @@ require 'cmpfs/version'
|
|
53
54
|
## Root module for *cmpfs*
|
54
55
|
module CmpFS
|
55
56
|
|
56
|
-
|
57
|
+
def self.extended receiver
|
57
58
|
|
58
|
-
|
59
|
+
receiver.class_eval do
|
59
60
|
|
60
|
-
|
61
|
-
|
61
|
+
extend CmpFS::Compare
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
64
|
+
$stderr.puts "#{receiver} extended by #{CmpFS}" if $DEBUG
|
65
|
+
end
|
65
66
|
|
66
|
-
|
67
|
+
def self.included receiver
|
67
68
|
|
68
|
-
|
69
|
+
receiver.class_eval do
|
69
70
|
|
70
|
-
|
71
|
-
|
71
|
+
include CmpFS::Compare
|
72
|
+
end
|
72
73
|
|
73
|
-
|
74
|
-
|
74
|
+
$stderr.puts "#{receiver} included #{CmpFS}" if $DEBUG
|
75
|
+
end
|
75
76
|
|
76
77
|
end # module CmpFS
|
77
78
|
|
79
|
+
|
80
|
+
# ############################## end of file ############################# #
|
81
|
+
|