hirb 0.5.0 → 0.6.0
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.
- data/.gemspec +1 -2
- data/CHANGELOG.rdoc +4 -0
- data/lib/hirb/helpers.rb +1 -1
- data/lib/hirb/helpers/tab_table.rb +24 -0
- data/lib/hirb/helpers/table.rb +17 -12
- data/lib/hirb/version.rb +1 -1
- data/test/table_test.rb +29 -11
- data/test/util_test.rb +2 -2
- metadata +63 -60
data/.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
require 'rubygems' unless Object.const_defined?(:Gem)
|
3
3
|
require File.dirname(__FILE__) + "/lib/hirb/version"
|
4
|
-
|
4
|
+
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "hirb"
|
7
7
|
s.version = Hirb::VERSION
|
@@ -11,7 +11,6 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.summary = "A mini view framework for console/irb that's easy to use, even while under its influence."
|
12
12
|
s.description = "Hirb provides a mini view framework for console applications and uses it to improve ripl(irb)'s default inspect output. Given an object or array of objects, hirb renders a view based on the object's class and/or ancestry. Hirb offers reusable views in the form of helper classes. The two main helpers, Hirb::Helpers::Table and Hirb::Helpers::Tree, provide several options for generating ascii tables and trees. Using Hirb::Helpers::AutoTable, hirb has useful default views for at least ten popular database gems i.e. Rails' ActiveRecord::Base. Other than views, hirb offers a smart pager and a console menu. The smart pager only pages when the output exceeds the current screen size. The menu is used in conjunction with tables to offer two dimensional menus."
|
13
13
|
s.required_rubygems_version = ">= 1.3.5"
|
14
|
-
s.rubyforge_project = 'tagaholic'
|
15
14
|
s.add_development_dependency 'bacon', '>= 1.1.0'
|
16
15
|
s.add_development_dependency 'mocha', '>= 0.9.8'
|
17
16
|
s.add_development_dependency 'mocha-on-bacon', '>= 0.1.1'
|
data/CHANGELOG.rdoc
CHANGED
data/lib/hirb/helpers.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
class Hirb::Helpers::TabTable < Hirb::Helpers::Table
|
2
|
+
DELIM = "\t"
|
3
|
+
|
4
|
+
# Renders a tab-delimited table
|
5
|
+
def self.render(rows, options={})
|
6
|
+
new(rows, {:description => false}.merge(options)).render
|
7
|
+
end
|
8
|
+
|
9
|
+
def render_header
|
10
|
+
@headers ? render_table_header : []
|
11
|
+
end
|
12
|
+
|
13
|
+
def render_table_header
|
14
|
+
[ format_values(@headers).join(DELIM) ]
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_rows
|
18
|
+
@rows.map { |row| format_values(row).join(DELIM) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def render_footer
|
22
|
+
[]
|
23
|
+
end
|
24
|
+
end
|
data/lib/hirb/helpers/table.rb
CHANGED
@@ -17,7 +17,7 @@ module Hirb
|
|
17
17
|
# +---+---+
|
18
18
|
#
|
19
19
|
# By default, the fields/columns are the numerical indices of the array.
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# An array of hashes ie [{:age=>10, :weight=>100}, {:age=>80, :weight=>500}], would render:
|
22
22
|
# +-----+--------+
|
23
23
|
# | age | weight |
|
@@ -72,7 +72,7 @@ module Hirb
|
|
72
72
|
}
|
73
73
|
|
74
74
|
class << self
|
75
|
-
|
75
|
+
|
76
76
|
# Main method which returns a formatted table.
|
77
77
|
# ==== Options:
|
78
78
|
# [*:fields*] An array which overrides the default fields and can be used to indicate field order.
|
@@ -97,6 +97,7 @@ module Hirb
|
|
97
97
|
# [*:filter_classes*] Hash which maps classes to filters. Default is Hirb::Helpers::Table.filter_classes().
|
98
98
|
# [*:vertical*] When set to true, renders a vertical table using Hirb::Helpers::VerticalTable. Default is false.
|
99
99
|
# [*:unicode*] When set to true, renders a unicode table using Hirb::Helpers::UnicodeTable. Default is false.
|
100
|
+
# [*:tab*] When set to true, renders a tab-delimited table using Hirb::Helpers::TabTable. Default is false.
|
100
101
|
# [*:all_fields*] When set to true, renders fields in all rows. Valid only in rows that are hashes. Default is false.
|
101
102
|
# [*:description*] When set to true, renders row count description at bottom. Default is true.
|
102
103
|
# [*:escape_special_chars*] When set to true, escapes special characters \n,\t,\r so they don't disrupt tables. Default is false for
|
@@ -111,6 +112,7 @@ module Hirb
|
|
111
112
|
def render(rows, options={})
|
112
113
|
options[:vertical] ? Helpers::VerticalTable.render(rows, options) :
|
113
114
|
options[:unicode] ? Helpers::UnicodeTable.render(rows, options) :
|
115
|
+
options[:tab] ? Helpers::TabTable.render(rows, options) :
|
114
116
|
new(rows, options).render
|
115
117
|
rescue TooManyFieldsForWidthError
|
116
118
|
$stderr.puts "", "** Hirb Warning: Too many fields for the current width. Configure your width " +
|
@@ -224,19 +226,22 @@ module Hirb
|
|
224
226
|
|
225
227
|
def render_table_header
|
226
228
|
title_row = chars[:top][:vertical][:outside] + ' ' +
|
227
|
-
@
|
228
|
-
join(' ' + chars[:top][:vertical][:inside] +' ') +
|
229
|
+
format_values(@headers).join(' ' + chars[:top][:vertical][:inside] +' ') +
|
229
230
|
' ' + chars[:top][:vertical][:outside]
|
230
231
|
[render_border(:top), title_row, render_border(:middle)]
|
231
232
|
end
|
232
|
-
|
233
|
+
|
233
234
|
def render_border(which)
|
234
235
|
chars[which][:left] + chars[which][:horizontal] +
|
235
236
|
@fields.map {|f| chars[which][:horizontal] * @field_lengths[f] }.
|
236
237
|
join(chars[which][:horizontal] + chars[which][:center] + chars[which][:horizontal]) +
|
237
238
|
chars[which][:horizontal] + chars[which][:right]
|
238
239
|
end
|
239
|
-
|
240
|
+
|
241
|
+
def format_values(values)
|
242
|
+
@fields.map {|field| format_cell(values[field], @field_lengths[field]) }
|
243
|
+
end
|
244
|
+
|
240
245
|
def format_cell(value, cell_width)
|
241
246
|
text = String.size(value) > cell_width ?
|
242
247
|
(
|
@@ -247,17 +252,17 @@ module Hirb
|
|
247
252
|
|
248
253
|
def render_rows
|
249
254
|
@rows.map do |row|
|
250
|
-
|
251
|
-
|
252
|
-
|
255
|
+
chars[:bottom][:vertical][:outside] + ' ' +
|
256
|
+
format_values(row).join(' ' + chars[:bottom][:vertical][:inside] + ' ') +
|
257
|
+
' ' + chars[:bottom][:vertical][:outside]
|
253
258
|
end
|
254
259
|
end
|
255
|
-
|
260
|
+
|
256
261
|
def render_table_description
|
257
262
|
(@rows.length == 0) ? "0 rows in set" :
|
258
263
|
"#{@rows.length} #{@rows.length == 1 ? 'row' : 'rows'} in set"
|
259
264
|
end
|
260
|
-
|
265
|
+
|
261
266
|
def setup_field_lengths
|
262
267
|
@field_lengths = default_field_lengths
|
263
268
|
if @options[:resize]
|
@@ -334,7 +339,7 @@ module Hirb
|
|
334
339
|
}
|
335
340
|
}
|
336
341
|
end
|
337
|
-
|
342
|
+
|
338
343
|
# Converts an array to a hash mapping a numerical index to its array value.
|
339
344
|
def array_to_indices_hash(array)
|
340
345
|
array.inject({}) {|hash,e| hash[hash.size] = e; hash }
|
data/lib/hirb/version.rb
CHANGED
data/test/table_test.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Table" do
|
|
6
6
|
Helpers::Table.render(*args)
|
7
7
|
end
|
8
8
|
before_all { reset_config }
|
9
|
-
|
9
|
+
|
10
10
|
describe "basic table" do
|
11
11
|
it "renders" do
|
12
12
|
expected_table = <<-TABLE.unindent
|
@@ -20,7 +20,7 @@ describe "Table" do
|
|
20
20
|
TABLE
|
21
21
|
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}]).should == expected_table
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it "with no headers renders" do
|
25
25
|
expected_table = <<-TABLE.unindent
|
26
26
|
+---+---+
|
@@ -162,7 +162,7 @@ describe "Table" do
|
|
162
162
|
TABLE
|
163
163
|
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], :fields=>[:b, :a]).should == expected_table
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
it "fields option and array only rows" do
|
167
167
|
expected_table = <<-TABLE.unindent
|
168
168
|
+---+---+
|
@@ -180,7 +180,7 @@ describe "Table" do
|
|
180
180
|
table([{:f1=>1, :f2=>2}], options)
|
181
181
|
options[:fields].should == [:f1]
|
182
182
|
end
|
183
|
-
|
183
|
+
|
184
184
|
it "invalid fields option renders empty columns" do
|
185
185
|
expected_table = <<-TABLE.unindent
|
186
186
|
+---+---+
|
@@ -193,7 +193,7 @@ describe "Table" do
|
|
193
193
|
TABLE
|
194
194
|
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], :fields=>[:b, :c]).should == expected_table
|
195
195
|
end
|
196
|
-
|
196
|
+
|
197
197
|
it "grep_fields option and symbol fields" do
|
198
198
|
expected_table = <<-TABLE.unindent
|
199
199
|
+----+----+
|
@@ -229,7 +229,7 @@ describe "Table" do
|
|
229
229
|
TABLE
|
230
230
|
table([{:a=> "A" * 50, :b=>2}], :max_fields=>{:a=>10,:c=>10}).should == expected_table
|
231
231
|
end
|
232
|
-
|
232
|
+
|
233
233
|
it "max_fields option with fields less than 3 characters renders" do
|
234
234
|
expected_table = <<-TABLE.unindent
|
235
235
|
+----+---+
|
@@ -241,7 +241,7 @@ describe "Table" do
|
|
241
241
|
TABLE
|
242
242
|
table([{:a=> "A" * 50, :b=>2}], :max_fields=>{:a=>2}, :resize=>false).should == expected_table
|
243
243
|
end
|
244
|
-
|
244
|
+
|
245
245
|
it "max_fields option without resize renders" do
|
246
246
|
expected_table = <<-TABLE.unindent
|
247
247
|
+------------+---+
|
@@ -265,7 +265,7 @@ describe "Table" do
|
|
265
265
|
TABLE
|
266
266
|
table([{:a=> "A" * 50, :b=>2}], :max_fields=>{:a=>'0.15'}).should == expected_table
|
267
267
|
end
|
268
|
-
|
268
|
+
|
269
269
|
it "max_width option renders" do
|
270
270
|
expected_table = <<-TABLE.unindent
|
271
271
|
+-----------+---+------------+
|
@@ -289,7 +289,7 @@ describe "Table" do
|
|
289
289
|
TABLE
|
290
290
|
table([{:a=> "A" * 50, :b=>2, :c=>"C"*10}], :resize=>false).should == expected_table
|
291
291
|
end
|
292
|
-
|
292
|
+
|
293
293
|
it "global width renders" do
|
294
294
|
expected_table = <<-TABLE.unindent
|
295
295
|
+-----------+---+------------+
|
@@ -316,7 +316,7 @@ describe "Table" do
|
|
316
316
|
TABLE
|
317
317
|
table([{:a=> "A", :b=>2, :c=>"C"}], :headers=>{:b=>"field B", :c=>"field C"}).should == expected_table
|
318
318
|
end
|
319
|
-
|
319
|
+
|
320
320
|
it "headers option and headers shortened by max_fields renders" do
|
321
321
|
expected_table = <<-TABLE.unindent
|
322
322
|
+-------+---+
|
@@ -328,7 +328,7 @@ describe "Table" do
|
|
328
328
|
TABLE
|
329
329
|
table([{:a=> "A", :b=>2}], :headers=>{:a=>"field A"}, :max_fields=>{:a=>5}, :resize=>false).should == expected_table
|
330
330
|
end
|
331
|
-
|
331
|
+
|
332
332
|
it "headers option as an array renders" do
|
333
333
|
expected_table = <<-TABLE.unindent
|
334
334
|
+---+---+
|
@@ -488,6 +488,24 @@ describe "Table" do
|
|
488
488
|
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], :unicode => true).should == expected_table
|
489
489
|
end
|
490
490
|
|
491
|
+
it "tab option renders" do
|
492
|
+
expected_table = <<-TABLE.unindent
|
493
|
+
a b
|
494
|
+
1 2
|
495
|
+
3 4
|
496
|
+
TABLE
|
497
|
+
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], :tab => true).should == expected_table
|
498
|
+
end
|
499
|
+
|
500
|
+
it "tab option with no headers renders" do
|
501
|
+
expected_table = <<-TABLE.unindent
|
502
|
+
1 2
|
503
|
+
3 4
|
504
|
+
TABLE
|
505
|
+
table([{:a=>1, :b=>2}, {:a=>3, :b=>4}], :tab => true, :headers => false).
|
506
|
+
should == expected_table
|
507
|
+
end
|
508
|
+
|
491
509
|
it "all_fields option renders all fields" do
|
492
510
|
expected_table = <<-TABLE.unindent
|
493
511
|
+---+---+---+
|
data/test/util_test.rb
CHANGED
@@ -7,7 +7,7 @@ describe "Util" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "any_const_get returns nested class" do
|
10
|
-
Util.any_const_get("
|
10
|
+
Util.any_const_get("Hirb::Helpers").should == Hirb::Helpers
|
11
11
|
end
|
12
12
|
|
13
13
|
it "any_const_get returns nil for invalid class" do
|
@@ -56,4 +56,4 @@ describe "Util" do
|
|
56
56
|
string = "sweetness man"
|
57
57
|
Util.capture_stdout { puts string }.should == string + "\n"
|
58
58
|
end
|
59
|
-
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,72 +1,77 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: hirb
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.5.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Gabriel Horner
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-11-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: bacon
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2152986240 !ruby/object:Gem::Requirement
|
20
17
|
none: false
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
24
21
|
version: 1.1.0
|
25
22
|
type: :development
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: mocha
|
29
23
|
prerelease: false
|
30
|
-
|
24
|
+
version_requirements: *2152986240
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mocha
|
27
|
+
requirement: &2152985720 !ruby/object:Gem::Requirement
|
31
28
|
none: false
|
32
|
-
requirements:
|
33
|
-
- -
|
34
|
-
- !ruby/object:Gem::Version
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
35
32
|
version: 0.9.8
|
36
33
|
type: :development
|
37
|
-
version_requirements: *id002
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: mocha-on-bacon
|
40
34
|
prerelease: false
|
41
|
-
|
35
|
+
version_requirements: *2152985720
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mocha-on-bacon
|
38
|
+
requirement: &2152985220 !ruby/object:Gem::Requirement
|
42
39
|
none: false
|
43
|
-
requirements:
|
44
|
-
- -
|
45
|
-
- !ruby/object:Gem::Version
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
46
43
|
version: 0.1.1
|
47
44
|
type: :development
|
48
|
-
version_requirements: *id003
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: bacon-bits
|
51
45
|
prerelease: false
|
52
|
-
|
46
|
+
version_requirements: *2152985220
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bacon-bits
|
49
|
+
requirement: &2152984840 !ruby/object:Gem::Requirement
|
53
50
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version:
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
58
55
|
type: :development
|
59
|
-
|
60
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2152984840
|
58
|
+
description: Hirb provides a mini view framework for console applications and uses
|
59
|
+
it to improve ripl(irb)'s default inspect output. Given an object or array of objects,
|
60
|
+
hirb renders a view based on the object's class and/or ancestry. Hirb offers reusable
|
61
|
+
views in the form of helper classes. The two main helpers, Hirb::Helpers::Table
|
62
|
+
and Hirb::Helpers::Tree, provide several options for generating ascii tables and
|
63
|
+
trees. Using Hirb::Helpers::AutoTable, hirb has useful default views for at least
|
64
|
+
ten popular database gems i.e. Rails' ActiveRecord::Base. Other than views, hirb
|
65
|
+
offers a smart pager and a console menu. The smart pager only pages when the output
|
66
|
+
exceeds the current screen size. The menu is used in conjunction with tables to
|
67
|
+
offer two dimensional menus.
|
61
68
|
email: gabriel.horner@gmail.com
|
62
69
|
executables: []
|
63
|
-
|
64
70
|
extensions: []
|
65
|
-
|
66
|
-
extra_rdoc_files:
|
71
|
+
extra_rdoc_files:
|
67
72
|
- README.rdoc
|
68
73
|
- LICENSE.txt
|
69
|
-
files:
|
74
|
+
files:
|
70
75
|
- lib/bond/completions/hirb.rb
|
71
76
|
- lib/hirb/console.rb
|
72
77
|
- lib/hirb/dynamic_view.rb
|
@@ -74,6 +79,7 @@ files:
|
|
74
79
|
- lib/hirb/helpers/auto_table.rb
|
75
80
|
- lib/hirb/helpers/object_table.rb
|
76
81
|
- lib/hirb/helpers/parent_child_tree.rb
|
82
|
+
- lib/hirb/helpers/tab_table.rb
|
77
83
|
- lib/hirb/helpers/table/filters.rb
|
78
84
|
- lib/hirb/helpers/table/resizer.rb
|
79
85
|
- lib/hirb/helpers/table.rb
|
@@ -118,33 +124,30 @@ files:
|
|
118
124
|
- test/deps.rip
|
119
125
|
- Rakefile
|
120
126
|
- .gemspec
|
121
|
-
has_rdoc: true
|
122
127
|
homepage: http://tagaholic.me/hirb/
|
123
|
-
licenses:
|
128
|
+
licenses:
|
124
129
|
- MIT
|
125
130
|
post_install_message:
|
126
131
|
rdoc_options: []
|
127
|
-
|
128
|
-
require_paths:
|
132
|
+
require_paths:
|
129
133
|
- lib
|
130
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
135
|
none: false
|
132
|
-
requirements:
|
133
|
-
- -
|
134
|
-
- !ruby/object:Gem::Version
|
135
|
-
version:
|
136
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ! '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
141
|
none: false
|
138
|
-
requirements:
|
139
|
-
- -
|
140
|
-
- !ruby/object:Gem::Version
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
141
145
|
version: 1.3.5
|
142
146
|
requirements: []
|
143
|
-
|
144
|
-
|
145
|
-
rubygems_version: 1.6.2
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 1.8.10
|
146
149
|
signing_key:
|
147
150
|
specification_version: 3
|
148
|
-
summary: A mini view framework for console/irb that's easy to use, even while under
|
151
|
+
summary: A mini view framework for console/irb that's easy to use, even while under
|
152
|
+
its influence.
|
149
153
|
test_files: []
|
150
|
-
|