hirber 0.8.0 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gemspec +45 -11
- data/CHANGELOG.rdoc +15 -0
- data/README.md +232 -0
- data/README.rdoc +7 -1
- data/Rakefile +14 -8
- data/lib/hirb/helpers/table.rb +349 -325
- data/lib/hirb/helpers/unicode_table.rb +29 -6
- data/lib/hirb/version.rb +1 -1
- data/lib/hirb/view.rb +50 -11
- data/lib/{hirb.rb → hirber.rb} +0 -0
- data/spec/spec_helper.rb +63 -0
- data/spec/view_spec.rb +288 -0
- data/spec/views_spec.rb +54 -0
- data/test/test_helper.rb +9 -5
- metadata +63 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1ee5c1edfe858985de14a9f502d2676a4cc7fdd6ee3dd3665b1c2640fc669ef
|
4
|
+
data.tar.gz: 151dc6d1a877c5660dce189f215260d074fed5a6f8a11160967180a18d0f51b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 894680dbe92e74acaf64dba6c9c9d65160e782840c5bd3645dad991c014a659f462960194cbccabb73b72d32bba2dd4fd90cf2b314b47b34bb4f1d68620c1fb3
|
7
|
+
data.tar.gz: 31179b6027cf78c5e8debf04e199aa797154bbac401e5df9dbef4cd557abea0de9a62c40044dde3718dea9a94f287f4edee8e098734763282ab0bf96f1c12f76
|
data/.gemspec
CHANGED
@@ -1,21 +1,55 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require
|
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 = "hirber"
|
7
7
|
s.version = Hirb::VERSION
|
8
|
-
|
9
|
-
s.
|
8
|
+
|
9
|
+
s.authors = ["Gabriel Horner", "Aleksander Długopolski", "Marz Drel"]
|
10
|
+
s.email = "marzdrel@dotpro.org"
|
10
11
|
s.homepage = "http://tagaholic.me/hirb/"
|
11
|
-
|
12
|
-
s.
|
12
|
+
|
13
|
+
s.summary = <<~TXT.gsub(/[[:space:]]+/, " ").strip
|
14
|
+
A mini view framework for console/irb that's easy to use, even while under
|
15
|
+
its influence.
|
16
|
+
TXT
|
17
|
+
|
18
|
+
s.description = <<~TXT.gsub(/[[:space:]]+/, " ").strip
|
19
|
+
Hirb provides a mini view framework for console applications and uses
|
20
|
+
it to improve ripl(irb)'s default inspect output. Given an object or
|
21
|
+
array of objects, hirb renders a view based on the object's class and/or
|
22
|
+
ancestry. Hirb offers reusable views in the form of helper classes. The
|
23
|
+
two main helpers, Hirb::Helpers::Table and Hirb::Helpers::Tree,
|
24
|
+
provide several options for generating ascii tables and trees. Using
|
25
|
+
Hirb::Helpers::AutoTable, hirb has useful default views for at least ten
|
26
|
+
popular database gems i.e. Rails' ActiveRecord::Base. Other than views,
|
27
|
+
hirb offers a smart pager and a console menu. The smart pager only pages
|
28
|
+
when the output exceeds the current screen size. The menu is used in
|
29
|
+
conjunction with tables to offer two dimensional menus.
|
30
|
+
TXT
|
31
|
+
|
13
32
|
s.required_rubygems_version = ">= 1.3.5"
|
14
|
-
|
15
|
-
s.add_development_dependency
|
16
|
-
s.add_development_dependency
|
17
|
-
s.add_development_dependency
|
18
|
-
s.
|
33
|
+
|
34
|
+
s.add_development_dependency "rake"
|
35
|
+
s.add_development_dependency "pry"
|
36
|
+
s.add_development_dependency "rspec", ">= 3.9"
|
37
|
+
s.add_development_dependency "bacon", "~> 1.1"
|
38
|
+
s.add_development_dependency "mocha", "~> 0.12.1"
|
39
|
+
s.add_development_dependency "mocha-on-bacon", "~> 0.2.1"
|
40
|
+
s.add_development_dependency "bacon-bits", "~> 0.1"
|
41
|
+
|
42
|
+
s.files =
|
43
|
+
Dir.glob %w[
|
44
|
+
{lib,test,spec}/**/*.rb
|
45
|
+
bin/*
|
46
|
+
[A-Z]*.{txt,rdoc,md}
|
47
|
+
ext/**/*.{rb,c}
|
48
|
+
Rakefile
|
49
|
+
.gemspec
|
50
|
+
.travis.yml
|
51
|
+
]
|
52
|
+
|
19
53
|
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
20
|
-
s.license =
|
54
|
+
s.license = "MIT"
|
21
55
|
end
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
== 0.8.5
|
2
|
+
* Fix issues with loading Hirber when using Pry
|
3
|
+
|
4
|
+
== 0.8.4
|
5
|
+
* Fix version number issues
|
6
|
+
|
7
|
+
== 0.8.3
|
8
|
+
* Add autoloading support for pry-rails
|
9
|
+
|
10
|
+
== 0.8.2
|
11
|
+
* Rename entry to hirber.rb to make loading easier.
|
12
|
+
|
13
|
+
== 0.8.1
|
14
|
+
* Add compatiblity with Ruby 3.0.0
|
15
|
+
|
1
16
|
== 0.7.3
|
2
17
|
* Remove warnings
|
3
18
|
|
data/README.md
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
![build passing](https://circleci.com/gh/hirber/hirber.svg?style=svg)
|
2
|
+
|
3
|
+
## Preface
|
4
|
+
|
5
|
+
This gem is a direct fork of [Hirb](https://github.com/cldwalker/hirb) (0.7.3)
|
6
|
+
which appears to be unmaintained since 2015. New release of Ruby (2.7.2)
|
7
|
+
introduced a breaking change into one of the methods in IRB module, which made
|
8
|
+
this Gem partially unusable. This fork aims to fix incompatibility. Feel free
|
9
|
+
to open PRs if you have any ideas to extend the functionality.
|
10
|
+
|
11
|
+
## Description
|
12
|
+
|
13
|
+
Hirb provides a mini view framework for console applications and uses it to
|
14
|
+
improve ripl(irb)'s default inspect output. Given an object or array of
|
15
|
+
objects, hirb renders a view based on the object's class and/or ancestry. Hirb
|
16
|
+
offers reusable views in the form of helper classes. The two main helpers,
|
17
|
+
Hirb::Helpers::Table and Hirb::Helpers::Tree, provide several options for
|
18
|
+
generating ascii tables and trees. Using Hirb::Helpers::AutoTable, hirb has
|
19
|
+
useful default views for at least ten popular database gems i.e. Rails'
|
20
|
+
ActiveRecord::Base. Other than views, hirb offers a smart pager and a console
|
21
|
+
menu. The smart pager only pages when the output exceeds the current screen
|
22
|
+
size. The menu is used in conjunction with tables to offer [two dimensional menus](http://tagaholic.me/2010/02/16/two-dimensional-console-menus-with-hirb.html).
|
23
|
+
|
24
|
+
## Install
|
25
|
+
|
26
|
+
Install the gem with:
|
27
|
+
|
28
|
+
gem install hirber
|
29
|
+
|
30
|
+
For people using full-width unicode characters, install
|
31
|
+
[hirb-unicode](https://github.com/miaout17/hirb-unicode):
|
32
|
+
|
33
|
+
gem install hirb-unicode
|
34
|
+
|
35
|
+
## View Tutorials
|
36
|
+
|
37
|
+
* To create and configure views, see Hirb::View or [here if on the web](http://tagaholic.me/hirb/doc/classes/Hirb/View.html).
|
38
|
+
* To create dynamic views, see Hirb::DynamicView or [here if on the web](http://tagaholic.me/hirb/doc/classes/Hirb/DynamicView.html).
|
39
|
+
|
40
|
+
## Printing Ascii Tables
|
41
|
+
|
42
|
+
To print ascii tables from an array of arrays, hashes or any objects:
|
43
|
+
|
44
|
+
puts Hirb::Helpers::AutoTable.render(ARRAY_OF_OBJECTS)
|
45
|
+
|
46
|
+
Hirb will intelligently pick up on field names from an array of hashes and
|
47
|
+
create properly-aligned fields from an array of arrays. See
|
48
|
+
[here](http://tagaholic.me/2009/10/15/boson-and-hirb-interactions.html#hirbs_handy_tables) for examples.
|
49
|
+
|
50
|
+
## Rails Example
|
51
|
+
|
52
|
+
Let's load and enable the view framework:
|
53
|
+
$ rails console
|
54
|
+
Loading local environment (Rails 3.0.3)
|
55
|
+
>> require 'hirb'
|
56
|
+
=> true
|
57
|
+
>> Hirb.enable
|
58
|
+
=> nil
|
59
|
+
|
60
|
+
The default configuration provides table views for ActiveRecord::Base
|
61
|
+
descendants. If a class isn't configured, Hirb reverts to irb's default echo
|
62
|
+
mode.
|
63
|
+
>> Hirb::Formatter.dynamic_config['ActiveRecord::Base']
|
64
|
+
=> {:class=>Hirb::Helpers::AutoTable, :ancestor=>true}
|
65
|
+
|
66
|
+
# Tag is a model class and descendant of ActiveRecord::Base
|
67
|
+
>> Tag.last
|
68
|
+
+-----+-------------------------+-------------+---------------+-----------+-----------+-------+
|
69
|
+
| id | created_at | description | name | namespace | predicate | value |
|
70
|
+
+-----+-------------------------+-------------+---------------+-----------+-----------+-------+
|
71
|
+
| 907 | 2009-03-06 21:10:41 UTC | | gem:tags=yaml | gem | tags | yaml |
|
72
|
+
+-----+-------------------------+-------------+---------------+-----------+-----------+-------+
|
73
|
+
1 row in set
|
74
|
+
|
75
|
+
>> Hirb::Formatter.dynamic_config['String']
|
76
|
+
=> nil
|
77
|
+
>> 'plain ol irb'
|
78
|
+
=> 'plain ol irb'
|
79
|
+
>> Hirb::Formatter.dynamic_config['Symbol']
|
80
|
+
=> nil
|
81
|
+
>> :blah
|
82
|
+
=> :blah
|
83
|
+
|
84
|
+
From above you can see there are no views configured for a String or a Symbol
|
85
|
+
so Hirb defaults to irb's echo mode. On the other hand, Tag has a view thanks
|
86
|
+
to being a descendant of ActiveRecord::Base and there being an :ancestor
|
87
|
+
option.
|
88
|
+
|
89
|
+
Having seen hirb display views based on an output object's class, let's see it
|
90
|
+
handle an array of objects:
|
91
|
+
|
92
|
+
>> Tag.all :limit=>3, :order=>"id DESC"
|
93
|
+
+-----+-------------------------+-------------+-------------------+-----------+-----------+----------+
|
94
|
+
| id | created_at | description | name | namespace | predicate | value |
|
95
|
+
+-----+-------------------------+-------------+-------------------+-----------+-----------+----------+
|
96
|
+
| 907 | 2009-03-06 21:10:41 UTC | | gem:tags=yaml | gem | tags | yaml |
|
97
|
+
| 906 | 2009-03-06 08:47:04 UTC | | gem:tags=nomonkey | gem | tags | nomonkey |
|
98
|
+
| 905 | 2009-03-04 00:30:10 UTC | | article:tags=ruby | article | tags | ruby |
|
99
|
+
+-----+-------------------------+-------------+-------------------+-----------+-----------+----------+
|
100
|
+
3 rows in set
|
101
|
+
|
102
|
+
At any time you can disable Hirb if you really like irb's lovely echo mode:
|
103
|
+
>> Hirb.disable
|
104
|
+
=> nil
|
105
|
+
>> Tag.all :limit=>3, :order=>"id DESC"
|
106
|
+
=> [#<Tag id: 907, name: "gem:tags=yaml", description: nil, created_at: "2009-03-06 21:10:41",
|
107
|
+
namespace: "gem", predicate: "tags", value: "yaml">, #<Tag id: 906, name: "gem:tags=nomonkey",
|
108
|
+
description: nil, created_at: "2009-03-06 08:47:04", namespace: "gem", predicate: "tags", value:
|
109
|
+
"nomonkey">, #<Tag id: 905, name: "article:tags=ruby", description: nil, created_at: "2009-03-04
|
110
|
+
00:30:10", namespace: "article", predicate: "tags", value: "ruby">]
|
111
|
+
|
112
|
+
## Views: Anytime, Anywhere
|
113
|
+
|
114
|
+
While preconfigured tables are great for database records, sometimes you just
|
115
|
+
want to create tables/views for any output object:
|
116
|
+
|
117
|
+
#These examples don't need to have Hirb::View enabled.
|
118
|
+
>> Hirb.disable
|
119
|
+
=> nil
|
120
|
+
|
121
|
+
# Imports table() and view()
|
122
|
+
>> extend Hirb::Console
|
123
|
+
=> main
|
124
|
+
|
125
|
+
# Create a unicode table
|
126
|
+
>> table [[:a, :b, :c]], :unicode => true
|
127
|
+
┌───┬───┬───┐
|
128
|
+
│ 0 │ 1 │ 2 │
|
129
|
+
├───┼───┼───┤
|
130
|
+
│ a ╎ b ╎ c │
|
131
|
+
└───┴───┴───┘
|
132
|
+
1 row in set
|
133
|
+
|
134
|
+
# Creates github-markdown
|
135
|
+
>> table [[:a, :b, :c]], :markdown => true
|
136
|
+
| 0 | 1 | 2 |
|
137
|
+
|---|---|---|
|
138
|
+
| a | b | c |
|
139
|
+
|
140
|
+
# Create a table of Dates comparing them with different formats.
|
141
|
+
>> table [Date.today, Date.today.next_month], :fields=>[:to_s, :ld, :ajd, :amjd, :asctime]
|
142
|
+
+------------+--------+-----------+-------+--------------------------+
|
143
|
+
| to_s | ld | ajd | amjd | asctime |
|
144
|
+
+------------+--------+-----------+-------+--------------------------+
|
145
|
+
| 2009-03-11 | 155742 | 4909803/2 | 54901 | Wed Mar 11 00:00:00 2009 |
|
146
|
+
| 2009-04-11 | 155773 | 4909865/2 | 54932 | Sat Apr 11 00:00:00 2009 |
|
147
|
+
+------------+--------+-----------+-------+--------------------------+
|
148
|
+
2 rows in set
|
149
|
+
|
150
|
+
# Same table as the previous method. However view() will be able to call any helper.
|
151
|
+
>> view [Date.today, Date.today.next_month], :class=>:object_table,
|
152
|
+
:fields=>[:to_s, :ld, :ajd, :amjd, :asctime]
|
153
|
+
|
154
|
+
If these console methods weren't convenient enough, try:
|
155
|
+
|
156
|
+
# Imports view() to all objects.
|
157
|
+
>> require 'hirb/import_object'
|
158
|
+
=> true
|
159
|
+
# Yields same table as above examples.
|
160
|
+
>> [Date.today, Date.today.next_month].view :class=>:object_table,
|
161
|
+
:fields=>[:to_s, :ld, :ajd, :amjd, :asctime]
|
162
|
+
|
163
|
+
Although views by default are printed to STDOUT, they can be easily modified
|
164
|
+
to write anywhere:
|
165
|
+
# Setup views to write to file 'console.log'.
|
166
|
+
>> Hirb::View.render_method = lambda {|output| File.open("console.log", 'w') {|f| f.write(output) } }
|
167
|
+
|
168
|
+
# Writes to file with same table output as above example.
|
169
|
+
>> view [Date.today, Date.today.next_month], :class=>:object_table,
|
170
|
+
:fields=>[:to_s, :ld, :ajd, :amjd, :asctime]
|
171
|
+
|
172
|
+
# Doesn't write to file because Symbol doesn't have a view and thus defaults to irb's echo mode.
|
173
|
+
>> :blah
|
174
|
+
=> :blah
|
175
|
+
|
176
|
+
# Go back to printing Hirb views to STDOUT.
|
177
|
+
>> Hirb::View.reset_render_method
|
178
|
+
|
179
|
+
## Pager
|
180
|
+
|
181
|
+
Hirb has both pager and formatter functionality enabled by default. Note - if
|
182
|
+
you copy and paste into your ruby console and think that one of your lines
|
183
|
+
will kick off the pager, be aware that subsequent characters will go to your
|
184
|
+
pager and could cause side effects like saving a file.
|
185
|
+
|
186
|
+
If you want to turn off the functionality of either pager or formatter, pass
|
187
|
+
that in at startup:
|
188
|
+
|
189
|
+
Hirb.enable :pager=>false
|
190
|
+
Hirb.enable :formatter=>false
|
191
|
+
|
192
|
+
or toggle their state at runtime:
|
193
|
+
|
194
|
+
Hirb::View.toggle_pager
|
195
|
+
Hirb::View.toggle_formatter
|
196
|
+
|
197
|
+
## Sharing Helpers and Views
|
198
|
+
|
199
|
+
If you have tested helpers you'd like to share, fork Hirb and put them under
|
200
|
+
lib/hirb/helpers. To share views for certain classes, put them under
|
201
|
+
lib/hirb/views. Please submit views for gems that have a nontrivial number of
|
202
|
+
users.
|
203
|
+
|
204
|
+
## Limitations
|
205
|
+
|
206
|
+
If using Wirble and irb, you should call Hirb after it since they both
|
207
|
+
override irb's default output.
|
208
|
+
|
209
|
+
## Motivation
|
210
|
+
|
211
|
+
Table code from http://gist.github.com/72234 and [my console app's needs](http://github.com/cldwalker/tag-tree).
|
212
|
+
|
213
|
+
## Credits
|
214
|
+
* Chrononaut for vertical table helper.
|
215
|
+
* janlelis for unicode table helper.
|
216
|
+
* technogeeky and FND for markdown table helper.
|
217
|
+
* hsume2, crafterm, spastorino, xaviershay, bogdan, asanghi, vwall,
|
218
|
+
maxmeyer, jimjh, ddoherty03, rochefort and joshua for patches.
|
219
|
+
|
220
|
+
|
221
|
+
## Bugs/Issues
|
222
|
+
|
223
|
+
Please report them [on github](http://github.com/cldwalker/hirb/issues).
|
224
|
+
|
225
|
+
## Contributing
|
226
|
+
[See here](http://tagaholic.me/contributing.html)
|
227
|
+
|
228
|
+
## Links
|
229
|
+
* http://tagaholic.me/2009/03/13/hirb-irb-on-the-good-stuff.html
|
230
|
+
* http://tagaholic.me/2009/03/18/ruby-class-trees-rails-plugin-trees-with-hirb.html
|
231
|
+
* http://tagaholic.me/2009/06/19/page-irb-output-and-improve-ri-with-hirb.html
|
232
|
+
|
data/README.rdoc
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
|
1
|
+
== Preface
|
2
|
+
|
3
|
+
This gem is a direct fork of {Hirb}[https://github.com/cldwalker/hirb]
|
4
|
+
(0.7.3) which appears to be unmaintained since 2015. New release of Ruby
|
5
|
+
(2.7.2) introduced a breaking change into one of the methods in IRB module,
|
6
|
+
which made this Gem partially unusable. This fork aims to fix incompatibility.
|
7
|
+
Feel free to open PRs if you have any ideas to extend the functionality.
|
2
8
|
|
3
9
|
== Description
|
4
10
|
|
data/Rakefile
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rake"
|
2
|
+
require "fileutils"
|
3
3
|
|
4
4
|
def gemspec
|
5
|
-
@gemspec ||= eval(File.read(
|
5
|
+
@gemspec ||= eval(File.read(".gemspec"), binding, ".gemspec")
|
6
6
|
end
|
7
7
|
|
8
8
|
desc "Build the gem"
|
9
|
-
task :gem
|
9
|
+
task :gem => :gemspec do
|
10
10
|
sh "gem build .gemspec"
|
11
|
-
|
12
|
-
FileUtils.
|
11
|
+
|
12
|
+
FileUtils.mkdir_p "pkg"
|
13
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", "pkg"
|
13
14
|
end
|
14
15
|
|
15
16
|
desc "Install the gem locally"
|
@@ -27,9 +28,14 @@ task :gemspec do
|
|
27
28
|
gemspec.validate
|
28
29
|
end
|
29
30
|
|
30
|
-
desc
|
31
|
+
desc "Run spec"
|
32
|
+
task :spec do
|
33
|
+
sh "rspec"
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Run tests"
|
31
37
|
task :test do |t|
|
32
|
-
sh
|
38
|
+
sh "bacon -q -Ilib -I. test/*_test.rb"
|
33
39
|
end
|
34
40
|
|
35
41
|
task :default => :test
|