coopy 0.6.4.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +7 -0
- data/LICENSE.md +22 -0
- data/README.md +59 -0
- data/Rakefile +4 -6
- data/coopy.gemspec +26 -0
- data/lib/coopy.rb +32 -175
- data/lib/coopy/alignment.rb +260 -0
- data/lib/coopy/bag.rb +17 -0
- data/lib/coopy/cell_info.rb +24 -0
- data/lib/coopy/change_type.rb +10 -0
- data/lib/coopy/compare_flags.rb +62 -0
- data/lib/coopy/compare_table.rb +327 -0
- data/lib/coopy/coopy.rb +22 -0
- data/lib/coopy/cross_match.rb +10 -0
- data/lib/coopy/csv_table.rb +51 -0
- data/lib/coopy/diff_render.rb +307 -0
- data/lib/coopy/index.rb +73 -0
- data/lib/coopy/index_item.rb +17 -0
- data/lib/coopy/index_pair.rb +72 -0
- data/lib/coopy/mover.rb +123 -0
- data/lib/coopy/ordering.rb +27 -0
- data/lib/coopy/row.rb +9 -0
- data/lib/coopy/simple_cell.rb +15 -0
- data/lib/coopy/simple_table.rb +144 -0
- data/lib/coopy/simple_view.rb +36 -0
- data/lib/coopy/table.rb +44 -0
- data/lib/coopy/table_comparison_state.rb +33 -0
- data/lib/coopy/table_diff.rb +634 -0
- data/lib/coopy/table_text.rb +14 -0
- data/lib/coopy/table_view.rb +31 -0
- data/lib/coopy/unit.rb +53 -0
- data/lib/coopy/version.rb +3 -0
- data/lib/coopy/view.rb +34 -0
- data/spec/fixtures/bridges.html +10 -0
- data/spec/fixtures/bridges_diff.csv +8 -0
- data/spec/fixtures/bridges_new.csv +9 -0
- data/spec/fixtures/bridges_old.csv +9 -0
- data/spec/fixtures/planetary_bodies.html +22 -0
- data/spec/fixtures/planetary_bodies_diff.csv +19 -0
- data/spec/fixtures/planetary_bodies_new.csv +20 -0
- data/spec/fixtures/planetary_bodies_old.csv +19 -0
- data/spec/fixtures/quote_me.csv +10 -0
- data/spec/fixtures/quote_me2.csv +11 -0
- data/spec/integration/table_diff_spec.rb +57 -0
- data/spec/libs/compare_flags_spec.rb +40 -0
- data/spec/libs/coopy_spec.rb +14 -0
- data/spec/libs/ordering_spec.rb +28 -0
- data/spec/libs/unit_spec.rb +31 -0
- data/spec/spec_helper.rb +29 -0
- metadata +153 -46
- data/bin/sqlite_diff +0 -4
- data/bin/sqlite_patch +0 -4
- data/bin/sqlite_rediff +0 -4
- data/lib/coopy/dbi_sql_wrapper.rb +0 -89
- data/lib/coopy/diff_apply_sql.rb +0 -35
- data/lib/coopy/diff_columns.rb +0 -33
- data/lib/coopy/diff_output.rb +0 -21
- data/lib/coopy/diff_output_action.rb +0 -34
- data/lib/coopy/diff_output_group.rb +0 -40
- data/lib/coopy/diff_output_raw.rb +0 -17
- data/lib/coopy/diff_output_stats.rb +0 -45
- data/lib/coopy/diff_output_table.rb +0 -49
- data/lib/coopy/diff_output_tdiff.rb +0 -48
- data/lib/coopy/diff_parser.rb +0 -92
- data/lib/coopy/diff_render_csv.rb +0 -29
- data/lib/coopy/diff_render_html.rb +0 -74
- data/lib/coopy/diff_render_log.rb +0 -52
- data/lib/coopy/row_change.rb +0 -25
- data/lib/coopy/scraperwiki_sql_wrapper.rb +0 -8
- data/lib/coopy/scraperwiki_utils.rb +0 -23
- data/lib/coopy/sequel_sql_wrapper.rb +0 -73
- data/lib/coopy/sql_compare.rb +0 -222
- data/lib/coopy/sql_wrapper.rb +0 -34
- data/lib/coopy/sqlite_sql_wrapper.rb +0 -143
- data/test/test_coopy.rb +0 -126
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
|
6
|
+
require 'simplecov'
|
7
|
+
require 'simplecov-rcov'
|
8
|
+
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
9
|
+
SimpleCov.start
|
10
|
+
|
11
|
+
require 'pry'
|
12
|
+
require 'coopy'
|
13
|
+
|
14
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
17
|
+
config.run_all_when_everything_filtered = true
|
18
|
+
config.filter_run :focus
|
19
|
+
|
20
|
+
# Run specs in random order to surface order dependencies. If you find an
|
21
|
+
# order dependency and want to debug it, you can fix the order by providing
|
22
|
+
# the seed, which is printed after each run.
|
23
|
+
# --seed 1234
|
24
|
+
config.order = 'random'
|
25
|
+
end
|
26
|
+
|
27
|
+
def load_fixture(file_name)
|
28
|
+
File.read(File.join('spec', 'fixtures', file_name))
|
29
|
+
end
|
metadata
CHANGED
@@ -1,75 +1,182 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coopy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
|
-
-
|
7
|
+
- James Smith
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
-
|
19
|
-
-
|
11
|
+
date: 2013-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov-rcov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Ruby port of coopyhx, for calculating tabular diffs
|
84
|
+
email:
|
85
|
+
- james@floppy.org.uk
|
86
|
+
executables: []
|
20
87
|
extensions: []
|
21
88
|
extra_rdoc_files: []
|
22
89
|
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- CHANGELOG.md
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.md
|
95
|
+
- README.md
|
23
96
|
- Rakefile
|
97
|
+
- coopy.gemspec
|
24
98
|
- lib/coopy.rb
|
25
|
-
- lib/coopy/
|
26
|
-
- lib/coopy/
|
27
|
-
- lib/coopy/
|
28
|
-
- lib/coopy/
|
29
|
-
- lib/coopy/
|
30
|
-
- lib/coopy/
|
31
|
-
- lib/coopy/
|
32
|
-
- lib/coopy/
|
33
|
-
- lib/coopy/
|
34
|
-
- lib/coopy/
|
35
|
-
- lib/coopy/
|
36
|
-
- lib/coopy/
|
37
|
-
- lib/coopy/
|
38
|
-
- lib/coopy/
|
39
|
-
- lib/coopy/
|
40
|
-
- lib/coopy/
|
41
|
-
- lib/coopy/
|
42
|
-
- lib/coopy/
|
43
|
-
- lib/coopy/
|
44
|
-
- lib/coopy/
|
45
|
-
- lib/coopy/
|
46
|
-
-
|
47
|
-
-
|
48
|
-
-
|
49
|
-
-
|
50
|
-
|
51
|
-
|
99
|
+
- lib/coopy/alignment.rb
|
100
|
+
- lib/coopy/bag.rb
|
101
|
+
- lib/coopy/cell_info.rb
|
102
|
+
- lib/coopy/change_type.rb
|
103
|
+
- lib/coopy/compare_flags.rb
|
104
|
+
- lib/coopy/compare_table.rb
|
105
|
+
- lib/coopy/coopy.rb
|
106
|
+
- lib/coopy/cross_match.rb
|
107
|
+
- lib/coopy/csv_table.rb
|
108
|
+
- lib/coopy/diff_render.rb
|
109
|
+
- lib/coopy/index.rb
|
110
|
+
- lib/coopy/index_item.rb
|
111
|
+
- lib/coopy/index_pair.rb
|
112
|
+
- lib/coopy/mover.rb
|
113
|
+
- lib/coopy/ordering.rb
|
114
|
+
- lib/coopy/row.rb
|
115
|
+
- lib/coopy/simple_cell.rb
|
116
|
+
- lib/coopy/simple_table.rb
|
117
|
+
- lib/coopy/simple_view.rb
|
118
|
+
- lib/coopy/table.rb
|
119
|
+
- lib/coopy/table_comparison_state.rb
|
120
|
+
- lib/coopy/table_diff.rb
|
121
|
+
- lib/coopy/table_text.rb
|
122
|
+
- lib/coopy/table_view.rb
|
123
|
+
- lib/coopy/unit.rb
|
124
|
+
- lib/coopy/version.rb
|
125
|
+
- lib/coopy/view.rb
|
126
|
+
- spec/fixtures/bridges.html
|
127
|
+
- spec/fixtures/bridges_diff.csv
|
128
|
+
- spec/fixtures/bridges_new.csv
|
129
|
+
- spec/fixtures/bridges_old.csv
|
130
|
+
- spec/fixtures/planetary_bodies.html
|
131
|
+
- spec/fixtures/planetary_bodies_diff.csv
|
132
|
+
- spec/fixtures/planetary_bodies_new.csv
|
133
|
+
- spec/fixtures/planetary_bodies_old.csv
|
134
|
+
- spec/fixtures/quote_me.csv
|
135
|
+
- spec/fixtures/quote_me2.csv
|
136
|
+
- spec/integration/table_diff_spec.rb
|
137
|
+
- spec/libs/compare_flags_spec.rb
|
138
|
+
- spec/libs/coopy_spec.rb
|
139
|
+
- spec/libs/ordering_spec.rb
|
140
|
+
- spec/libs/unit_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
homepage: ''
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
metadata: {}
|
52
146
|
post_install_message:
|
53
147
|
rdoc_options: []
|
54
148
|
require_paths:
|
55
149
|
- lib
|
56
150
|
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
151
|
requirements:
|
59
|
-
- -
|
152
|
+
- - '>='
|
60
153
|
- !ruby/object:Gem::Version
|
61
154
|
version: '0'
|
62
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
156
|
requirements:
|
65
|
-
- -
|
157
|
+
- - '>='
|
66
158
|
- !ruby/object:Gem::Version
|
67
159
|
version: '0'
|
68
160
|
requirements: []
|
69
161
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.
|
162
|
+
rubygems_version: 2.1.10
|
71
163
|
signing_key:
|
72
|
-
specification_version:
|
73
|
-
summary:
|
164
|
+
specification_version: 4
|
165
|
+
summary: Ruby port of coopyhx, for calculating tabular diffs
|
74
166
|
test_files:
|
75
|
-
-
|
167
|
+
- spec/fixtures/bridges.html
|
168
|
+
- spec/fixtures/bridges_diff.csv
|
169
|
+
- spec/fixtures/bridges_new.csv
|
170
|
+
- spec/fixtures/bridges_old.csv
|
171
|
+
- spec/fixtures/planetary_bodies.html
|
172
|
+
- spec/fixtures/planetary_bodies_diff.csv
|
173
|
+
- spec/fixtures/planetary_bodies_new.csv
|
174
|
+
- spec/fixtures/planetary_bodies_old.csv
|
175
|
+
- spec/fixtures/quote_me.csv
|
176
|
+
- spec/fixtures/quote_me2.csv
|
177
|
+
- spec/integration/table_diff_spec.rb
|
178
|
+
- spec/libs/compare_flags_spec.rb
|
179
|
+
- spec/libs/coopy_spec.rb
|
180
|
+
- spec/libs/ordering_spec.rb
|
181
|
+
- spec/libs/unit_spec.rb
|
182
|
+
- spec/spec_helper.rb
|
data/bin/sqlite_diff
DELETED
data/bin/sqlite_patch
DELETED
data/bin/sqlite_rediff
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'sql_wrapper'
|
2
|
-
require 'dbi'
|
3
|
-
|
4
|
-
class Coopy::DbiSqlWrapper < SqlWrapper
|
5
|
-
def initialize(db)
|
6
|
-
@db = db
|
7
|
-
@t = nil
|
8
|
-
@qt = nil
|
9
|
-
end
|
10
|
-
|
11
|
-
def complete_table(tbl)
|
12
|
-
return tbl unless tbl.nil?
|
13
|
-
return @t unless @t.nil?
|
14
|
-
@t = @db.tables[0]
|
15
|
-
@t
|
16
|
-
end
|
17
|
-
|
18
|
-
def quote_table(tbl)
|
19
|
-
return @db.quote(tbl) unless tbl.nil?
|
20
|
-
return @qt unless @qt.nil?
|
21
|
-
@t = @db.tables[0]
|
22
|
-
@qt = @db.quote(@t)
|
23
|
-
@qt
|
24
|
-
end
|
25
|
-
|
26
|
-
def insert(tbl,cols,vals)
|
27
|
-
tbl = quote_table(tbl)
|
28
|
-
template = cols.map{|x| '?'}.join(",")
|
29
|
-
template = "INSERT INTO #{tbl} VALUES(#{template})"
|
30
|
-
stmt = @db.prepare(template)
|
31
|
-
stmt.execute(*vals)
|
32
|
-
stmt.finish
|
33
|
-
end
|
34
|
-
|
35
|
-
def delete(tbl,cols,vals)
|
36
|
-
tbl = quote_table(tbl)
|
37
|
-
template = cols.map{|c| @db.quote(c) + ' = ?'}.join(" AND ")
|
38
|
-
template = "DELETE FROM #{tbl} WHERE #{template}"
|
39
|
-
stmt = @db.prepare(template)
|
40
|
-
stmt.execute(*vals)
|
41
|
-
stmt.finish
|
42
|
-
end
|
43
|
-
|
44
|
-
def update(tbl,set_cols,set_vals,cond_cols,cond_vals)
|
45
|
-
tbl = quote_table(tbl)
|
46
|
-
conds = cond_cols.map{|c| @db.quote(c) + ' = ?'}.join(" AND ")
|
47
|
-
sets = set_cols.map{|c| @db.quote(c) + ' = ?'}.join(", ")
|
48
|
-
template = "UPDATE #{@qt} SET #{sets} WHERE #{conds}"
|
49
|
-
v = set_vals + cond_vals
|
50
|
-
stmt = @db.prepare(template)
|
51
|
-
stmt.execute(*v)
|
52
|
-
stmt.finish
|
53
|
-
end
|
54
|
-
|
55
|
-
def transaction(&block)
|
56
|
-
@db["AutoCommit"]=false
|
57
|
-
begin
|
58
|
-
block.call
|
59
|
-
@db.commit
|
60
|
-
rescue Exception => e
|
61
|
-
@db.rollback
|
62
|
-
raise e
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def columns(tbl)
|
67
|
-
tbl = complete_table(tbl)
|
68
|
-
@db.columns(tbl)
|
69
|
-
end
|
70
|
-
|
71
|
-
def column_names(tbl)
|
72
|
-
columns(tbl).map{|c| c[:name]}
|
73
|
-
end
|
74
|
-
|
75
|
-
def enhash(cols,vals)
|
76
|
-
Hash[*cols.map{|c| c.to_sym}.zip(vals).flatten]
|
77
|
-
end
|
78
|
-
|
79
|
-
def fetch(sql,names)
|
80
|
-
@db.select_all(sql) do |row|
|
81
|
-
yield row
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def primary_key(tbl)
|
86
|
-
# don't seem to have this information? oy.
|
87
|
-
[column_names(tbl)[0]]
|
88
|
-
end
|
89
|
-
end
|
data/lib/coopy/diff_apply_sql.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'coopy/diff_output_action'
|
2
|
-
require 'coopy/sql_wrapper'
|
3
|
-
|
4
|
-
# for now, assume no schema changes, and a single table
|
5
|
-
class Coopy::DiffApplySql < DiffOutputAction
|
6
|
-
def initialize(db, name = nil)
|
7
|
-
@name = name
|
8
|
-
@db = db
|
9
|
-
end
|
10
|
-
|
11
|
-
def row_insert(rc)
|
12
|
-
cols = rc.active_columns
|
13
|
-
@db.insert(@name,
|
14
|
-
cols.map{|c| c[:title]},
|
15
|
-
cols.map{|c| rc.value_at(c)})
|
16
|
-
end
|
17
|
-
|
18
|
-
def row_delete(rc)
|
19
|
-
cols = rc.active_columns
|
20
|
-
@db.delete(@name,
|
21
|
-
cols.map{|c| c[:title]},
|
22
|
-
cols.map{|c| rc.value_at(c)})
|
23
|
-
end
|
24
|
-
|
25
|
-
def row_update(rc)
|
26
|
-
cols = rc.active_columns
|
27
|
-
touched_cols = cols.select{|c| !rc.new_value_at(c).nil?}
|
28
|
-
@db.update(@name,
|
29
|
-
touched_cols.map{|c| c[:title]},
|
30
|
-
touched_cols.map{|c| rc.new_value_at(c)},
|
31
|
-
cols.map{|c| c[:title]},
|
32
|
-
cols.map{|c| rc.value_at(c)})
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
data/lib/coopy/diff_columns.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
class DiffColumns
|
2
|
-
attr_accessor :change_row
|
3
|
-
attr_accessor :title_row
|
4
|
-
|
5
|
-
# general
|
6
|
-
attr_accessor :column_name # *after* any column changes
|
7
|
-
attr_accessor :column_offset # *after* any column changes
|
8
|
-
attr_accessor :column_by_name
|
9
|
-
attr_accessor :column_by_offset
|
10
|
-
|
11
|
-
def update(prefix=1)
|
12
|
-
return if @title_row.nil?
|
13
|
-
@column_name = {}
|
14
|
-
@column_offset = {}
|
15
|
-
@column_by_name = {}
|
16
|
-
@column_by_offset = []
|
17
|
-
offset = -prefix
|
18
|
-
@title_row.each_with_index do |title,idx|
|
19
|
-
@column_name[idx] = title
|
20
|
-
if offset>=0
|
21
|
-
# assuming no column changes for the moment
|
22
|
-
@column_offset[idx] = offset
|
23
|
-
@column_by_name[title] = {
|
24
|
-
:title => title,
|
25
|
-
:in_offset => offset,
|
26
|
-
:diff_offset => idx
|
27
|
-
}
|
28
|
-
@column_by_offset << @column_by_name[title]
|
29
|
-
end
|
30
|
-
offset = offset+1
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/coopy/diff_output.rb
DELETED