tablesmith 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -1
- data/.rubocop.yml +112 -2
- data/.ruby-version +1 -1
- data/.travis.yml +21 -0
- data/Appraisals +19 -0
- data/Gemfile +2 -0
- data/README.md +112 -11
- data/Rakefile +4 -2
- data/gemfiles/activerecord_4.gemfile +8 -0
- data/gemfiles/activerecord_5.1.gemfile +8 -0
- data/gemfiles/activerecord_5.2.gemfile +8 -0
- data/gemfiles/activerecord_6.0.gemfile +8 -0
- data/lib/tablesmith.rb +2 -0
- data/lib/tablesmith/active_record_source.rb +4 -2
- data/lib/tablesmith/array_rows_source.rb +3 -1
- data/lib/tablesmith/hash_rows_base.rb +4 -1
- data/lib/tablesmith/hash_rows_source.rb +8 -8
- data/lib/tablesmith/html_formatter.rb +1 -0
- data/lib/tablesmith/table.rb +34 -32
- data/lib/tablesmith/version.rb +3 -1
- data/spec/active_record_table_spec.rb +51 -49
- data/spec/array_table_spec.rb +61 -2
- data/spec/fixtures.rb +2 -0
- data/spec/hash_rows_table_spec.rb +15 -12
- data/spec/hash_table_spec.rb +23 -1
- data/spec/spec_helper.rb +6 -2
- data/spec/table_spec.rb +5 -3
- data/tablesmith.gemspec +15 -10
- metadata +77 -15
data/spec/array_table_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'Array Source' do
|
@@ -9,6 +11,63 @@ describe 'Array Source' do
|
|
9
11
|
| d | e | f |
|
10
12
|
+---+---+---+
|
11
13
|
TABLE
|
12
|
-
[%w
|
14
|
+
[%w[a b c], %w[d e f]].to_table.to_s.should == expected
|
15
|
+
end
|
16
|
+
|
17
|
+
def do_just_works_test(_expected, meth_id)
|
18
|
+
orig_stdout = $stdout
|
19
|
+
sio = StringIO.new
|
20
|
+
$stdout = sio
|
21
|
+
send(meth_id, [%w[a b c], %w[d e f]].to_table)
|
22
|
+
sio.string
|
23
|
+
ensure
|
24
|
+
$stdout = orig_stdout
|
25
|
+
end
|
26
|
+
|
27
|
+
def just_works(meth_id)
|
28
|
+
expected = <<~TABLE
|
29
|
+
+---+---+---+
|
30
|
+
| a | b | c |
|
31
|
+
+---+---+---+
|
32
|
+
| d | e | f |
|
33
|
+
+---+---+---+
|
34
|
+
TABLE
|
35
|
+
|
36
|
+
actual = do_just_works_test(expected, meth_id)
|
37
|
+
actual.should == expected
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'just works with print' do
|
41
|
+
just_works(:print)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'just works with puts' do
|
45
|
+
pending
|
46
|
+
|
47
|
+
# Kernel.puts has special behavior for puts with Array,
|
48
|
+
# which Table subclasses, so this isn't going to work,
|
49
|
+
# unless we can stop subclassing Array.
|
50
|
+
just_works(:puts)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'just works with inspect' do
|
54
|
+
expected = <<~TABLE
|
55
|
+
+---+---+---+
|
56
|
+
| a | b | c |
|
57
|
+
+---+---+---+
|
58
|
+
| d | e | f |
|
59
|
+
+---+---+---+
|
60
|
+
TABLE
|
61
|
+
[%w[a b c], %w[d e f]].to_table.inspect.should == expected
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'just works with inspect two element integer array' do
|
65
|
+
expected = <<~TABLE
|
66
|
+
+---+
|
67
|
+
| 1 |
|
68
|
+
| 3 |
|
69
|
+
+---+
|
70
|
+
TABLE
|
71
|
+
[1, 3].to_table.inspect.should == expected
|
13
72
|
end
|
14
|
-
end
|
73
|
+
end
|
data/spec/fixtures.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'HashRowsSource' do
|
@@ -9,7 +11,7 @@ describe 'HashRowsSource' do
|
|
9
11
|
| 1 | 2 |
|
10
12
|
+---+---+
|
11
13
|
TABLE
|
12
|
-
[{a: 1, b: 2}].to_table.
|
14
|
+
[{ a: 1, b: 2 }].to_table.to_s.should == expected
|
13
15
|
end
|
14
16
|
|
15
17
|
it 'outputs text table of hash row with nested Array' do
|
@@ -20,7 +22,7 @@ describe 'HashRowsSource' do
|
|
20
22
|
| 1 | [1, 2] |
|
21
23
|
+---+--------+
|
22
24
|
TABLE
|
23
|
-
[{a: 1, b: [1, 2]}].to_table.
|
25
|
+
[{ a: 1, b: [1, 2] }].to_table.to_s.should == expected
|
24
26
|
end
|
25
27
|
|
26
28
|
it 'outputs text table of hash row with nested Hash' do
|
@@ -31,7 +33,7 @@ describe 'HashRowsSource' do
|
|
31
33
|
| 1 | {:c=>3} |
|
32
34
|
+---+---------+
|
33
35
|
TABLE
|
34
|
-
[{a: 1, b: {c: 3}}].to_table.
|
36
|
+
[{ a: 1, b: { c: 3 } }].to_table.to_s.should == expected
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'outputs text table of mixed columns hash rows with default columns' do
|
@@ -44,12 +46,14 @@ describe 'HashRowsSource' do
|
|
44
46
|
+---+---+---+
|
45
47
|
TABLE
|
46
48
|
[
|
47
|
-
{a: 1, b: 2},
|
48
|
-
{a: 2, c: '!'}
|
49
|
-
].to_table.
|
49
|
+
{ a: 1, b: 2 },
|
50
|
+
{ a: 2, c: '!' }
|
51
|
+
].to_table.to_s.should == expected
|
50
52
|
end
|
51
53
|
|
52
54
|
it 'outputs text table of deep hash rows with defined columns' do
|
55
|
+
pending
|
56
|
+
|
53
57
|
expected = <<~TABLE
|
54
58
|
+---+---+---+
|
55
59
|
| a | b |
|
@@ -59,19 +63,18 @@ describe 'HashRowsSource' do
|
|
59
63
|
| 1 | 2 | 2 |
|
60
64
|
+---+---+---+
|
61
65
|
TABLE
|
62
|
-
b = [{a: 1, b: {c: 2, d: 2}}].to_table
|
66
|
+
b = [{ a: 1, b: { c: 2, d: 2 } }].to_table
|
63
67
|
def b.columns
|
64
68
|
[
|
65
69
|
Column.new(name: :a),
|
66
|
-
{b: [
|
70
|
+
{ b: [
|
67
71
|
Column.new(name: :c)
|
68
|
-
]}
|
72
|
+
] }
|
69
73
|
]
|
70
74
|
end
|
71
75
|
|
72
76
|
# this would be nice.
|
73
|
-
|
74
|
-
pending
|
77
|
+
b.to_s.should == expected
|
75
78
|
end
|
76
79
|
|
77
80
|
it 'keeps OrderedHash keys in order' do
|
@@ -85,7 +88,7 @@ describe 'HashRowsSource' do
|
|
85
88
|
| 2 | 1 |
|
86
89
|
+---+---+
|
87
90
|
TABLE
|
88
|
-
h.to_table.
|
91
|
+
h.to_table.to_s.should == expected
|
89
92
|
end
|
90
93
|
|
91
94
|
it 'outputs text table of deep hash rows with default columns'
|
data/spec/hash_table_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'Hash Source' do
|
@@ -11,4 +13,24 @@ describe 'Hash Source' do
|
|
11
13
|
TABLE
|
12
14
|
{a: 1, b: 2, c: 3}.to_table.text_table.to_s.should == expected
|
13
15
|
end
|
14
|
-
|
16
|
+
|
17
|
+
it 'just works with print' do
|
18
|
+
expected = <<~TABLE
|
19
|
+
+---+---+---+
|
20
|
+
| a | b | c |
|
21
|
+
+---+---+---+
|
22
|
+
| 1 | 2 | 3 |
|
23
|
+
+---+---+---+
|
24
|
+
TABLE
|
25
|
+
|
26
|
+
begin
|
27
|
+
orig_stdout = $stdout
|
28
|
+
sio = StringIO.new
|
29
|
+
$stdout = sio
|
30
|
+
print({a: 1, b: 2, c: 3}.to_table)
|
31
|
+
sio.string.should == expected
|
32
|
+
ensure
|
33
|
+
$stdout = orig_stdout
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path('../
|
3
|
+
require File.expand_path('../lib/tablesmith', __dir__)
|
4
|
+
|
5
|
+
require File.expand_path('fixtures', __dir__)
|
6
|
+
|
7
|
+
RSpec.configuration.expect_with(:rspec) { |c| c.syntax = :should }
|
data/spec/table_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
include Tablesmith
|
5
|
+
include Tablesmith # rubocop:disable Style/MixinUsage:
|
4
6
|
|
5
7
|
describe Table do
|
6
8
|
it 'should subclass array' do
|
@@ -31,7 +33,7 @@ describe Table do
|
|
31
33
|
end
|
32
34
|
|
33
35
|
it 'should handle a simple two row Array' do
|
34
|
-
a = [%w
|
36
|
+
a = [%w[a b c], %w[d e f]]
|
35
37
|
actual = a
|
36
38
|
expected = <<~TABLE
|
37
39
|
+---+---+---+
|
@@ -44,7 +46,7 @@ describe Table do
|
|
44
46
|
end
|
45
47
|
|
46
48
|
it 'should output csv' do
|
47
|
-
a = [['a', 'b,s', 'c'], %w
|
49
|
+
a = [['a', 'b,s', 'c'], %w[d e f]]
|
48
50
|
actual = a
|
49
51
|
expected = <<~TABLE
|
50
52
|
a,"b,s",c
|
data/tablesmith.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'tablesmith/version'
|
5
6
|
|
@@ -8,21 +9,25 @@ Gem::Specification.new do |gem|
|
|
8
9
|
gem.version = Tablesmith::VERSION
|
9
10
|
gem.authors = ['chrismo']
|
10
11
|
gem.email = ['chrismo@clabs.org']
|
11
|
-
gem.description =
|
12
|
-
gem.summary =
|
12
|
+
gem.description = 'Minimal console table'
|
13
|
+
gem.summary = 'Minimal console table'
|
13
14
|
gem.homepage = 'http://github.com/livingsocial/tablesmith'
|
14
15
|
|
15
|
-
gem.files = `git ls-files`.split(
|
16
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
17
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
19
|
gem.require_paths = ['lib']
|
19
20
|
|
20
21
|
gem.add_dependency 'text-table'
|
21
22
|
|
22
|
-
gem.add_development_dependency 'activerecord', '~>
|
23
|
+
gem.add_development_dependency 'activerecord', '~> 4.0'
|
24
|
+
gem.add_development_dependency 'appraisal'
|
25
|
+
gem.add_development_dependency 'bundler', '~> 2.1'
|
23
26
|
gem.add_development_dependency 'pry'
|
24
|
-
gem.add_development_dependency 'rake', '
|
25
|
-
gem.add_development_dependency 'rspec', '~>
|
27
|
+
gem.add_development_dependency 'rake', '>= 12.3.3'
|
28
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
gem.add_development_dependency 'rubocop'
|
30
|
+
gem.add_development_dependency 'rubocop_lineup'
|
26
31
|
gem.add_development_dependency 'simplecov'
|
27
|
-
gem.add_development_dependency 'sqlite3'
|
32
|
+
gem.add_development_dependency 'sqlite3', '~> 1.3.6'
|
28
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tablesmith
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chrismo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: text-table
|
@@ -30,16 +30,16 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '4.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: appraisal
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,35 +53,63 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '2.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '2.1'
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 12.3.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 12.3.3
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: rspec
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - "~>"
|
74
102
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
103
|
+
version: '3.0'
|
76
104
|
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
108
|
- - "~>"
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
110
|
+
version: '3.0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
112
|
+
name: rubocop
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
115
|
- - ">="
|
@@ -95,7 +123,21 @@ dependencies:
|
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '0'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
126
|
+
name: rubocop_lineup
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
99
141
|
requirement: !ruby/object:Gem::Requirement
|
100
142
|
requirements:
|
101
143
|
- - ">="
|
@@ -108,10 +150,25 @@ dependencies:
|
|
108
150
|
- - ">="
|
109
151
|
- !ruby/object:Gem::Version
|
110
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sqlite3
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 1.3.6
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 1.3.6
|
111
167
|
description: Minimal console table
|
112
168
|
email:
|
113
169
|
- chrismo@clabs.org
|
114
|
-
executables:
|
170
|
+
executables:
|
171
|
+
- console
|
115
172
|
extensions: []
|
116
173
|
extra_rdoc_files: []
|
117
174
|
files:
|
@@ -120,10 +177,16 @@ files:
|
|
120
177
|
- ".rubocop.yml"
|
121
178
|
- ".ruby-version"
|
122
179
|
- ".travis.yml"
|
180
|
+
- Appraisals
|
123
181
|
- Gemfile
|
124
182
|
- LICENSE
|
125
183
|
- README.md
|
126
184
|
- Rakefile
|
185
|
+
- bin/console
|
186
|
+
- gemfiles/activerecord_4.gemfile
|
187
|
+
- gemfiles/activerecord_5.1.gemfile
|
188
|
+
- gemfiles/activerecord_5.2.gemfile
|
189
|
+
- gemfiles/activerecord_6.0.gemfile
|
127
190
|
- lib/tablesmith.rb
|
128
191
|
- lib/tablesmith/active_record_source.rb
|
129
192
|
- lib/tablesmith/array_rows_source.rb
|
@@ -158,8 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
221
|
- !ruby/object:Gem::Version
|
159
222
|
version: '0'
|
160
223
|
requirements: []
|
161
|
-
|
162
|
-
rubygems_version: 2.6.13
|
224
|
+
rubygems_version: 3.0.3
|
163
225
|
signing_key:
|
164
226
|
specification_version: 4
|
165
227
|
summary: Minimal console table
|