hirb 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemspec +1 -1
- data/CHANGELOG.rdoc +6 -0
- data/README.rdoc +1 -1
- data/lib/hirb/formatter.rb +4 -1
- data/lib/hirb/version.rb +1 -1
- data/lib/hirb/view.rb +21 -35
- data/lib/ripl/hirb.rb +14 -0
- data/test/formatter_test.rb +9 -4
- data/test/view_test.rb +0 -7
- metadata +8 -7
data/.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "http://tagaholic.me/hirb/"
|
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 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
|
-
s.required_rubygems_version = ">= 1.3.
|
13
|
+
s.required_rubygems_version = ">= 1.3.5"
|
14
14
|
s.rubyforge_project = 'tagaholic'
|
15
15
|
s.add_development_dependency 'bacon', '>= 1.1.0'
|
16
16
|
s.add_development_dependency 'mocha'
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 0.3.5
|
2
|
+
* Add ripl support
|
3
|
+
* Fix Formatter#determine_output_class for IO and Hash
|
4
|
+
* Remove :output_method option for Hirb.enable
|
5
|
+
* Allow rubygems 1.3.5
|
6
|
+
|
1
7
|
== 0.3.4
|
2
8
|
* Added auto format of array-like objects i.e. ActiveRecord::Relation and Set.
|
3
9
|
* Fixed bug when Hirb::Console#table is used without Hirb enabled.
|
data/README.rdoc
CHANGED
@@ -25,7 +25,7 @@ Install the gem with:
|
|
25
25
|
|
26
26
|
To print ascii tables from an array of arrays, hashes or any objects:
|
27
27
|
|
28
|
-
puts Hirb::
|
28
|
+
puts Hirb::Helpers::AutoTable.render(ARRAY_OF_OBJECTS)
|
29
29
|
|
30
30
|
Hirb will intelligently pick up on field names from an array of hashes and create properly-aligned
|
31
31
|
fields from an array of arrays. See
|
data/lib/hirb/formatter.rb
CHANGED
@@ -2,6 +2,8 @@ module Hirb
|
|
2
2
|
# A Formatter object formats an output object (using Formatter.format_output) into a string based on the views defined
|
3
3
|
# for its class and/or ancestry.
|
4
4
|
class Formatter
|
5
|
+
TO_A_EXCEPTIONS = ['Hash', 'IO']
|
6
|
+
|
5
7
|
class<<self
|
6
8
|
# This config is used by Formatter.format_output to lazily load dynamic views defined with Hirb::DynamicView.
|
7
9
|
# This hash has the same format as Formatter.config.
|
@@ -75,7 +77,8 @@ module Hirb
|
|
75
77
|
end
|
76
78
|
|
77
79
|
def determine_output_class(output)
|
78
|
-
output.respond_to?(:to_a) ?
|
80
|
+
output.respond_to?(:to_a) && !TO_A_EXCEPTIONS.include?(output.class.to_s) ?
|
81
|
+
Array(output)[0].class : output.class
|
79
82
|
end
|
80
83
|
|
81
84
|
def call_output_method(output_method, output)
|
data/lib/hirb/version.rb
CHANGED
data/lib/hirb/view.rb
CHANGED
@@ -72,18 +72,15 @@ module Hirb
|
|
72
72
|
# or as options to this method. In addition to the config keys mentioned in Hirb, options also take the following keys:
|
73
73
|
# ==== Options:
|
74
74
|
# * config_file: Name of config file(s) that are merged into existing config
|
75
|
-
# * output_method: Specify an object's class and instance method (separated by a period) to be realiased with
|
76
|
-
# hirb's view system. The instance method should take a string to be output. Default is IRB::Irb.output_value
|
77
|
-
# if using irb.
|
78
75
|
# Examples:
|
79
76
|
# Hirb.enable
|
80
|
-
# Hirb.enable :formatter=>false
|
77
|
+
# Hirb.enable :formatter=>false
|
81
78
|
def enable(options={}, &block)
|
82
79
|
Array(options.delete(:config_file)).each {|e|
|
83
80
|
@new_config_file = true
|
84
81
|
Hirb.config_files << e
|
85
82
|
}
|
86
|
-
enable_output_method
|
83
|
+
enable_output_method unless @output_method
|
87
84
|
merge_or_load_config options
|
88
85
|
resize(config[:width], config[:height])
|
89
86
|
@enabled = true
|
@@ -97,7 +94,7 @@ module Hirb
|
|
97
94
|
# Disable's Hirb's output and revert's irb's output method if irb exists.
|
98
95
|
def disable
|
99
96
|
@enabled = false
|
100
|
-
|
97
|
+
disable_output_method if @output_method
|
101
98
|
false
|
102
99
|
end
|
103
100
|
|
@@ -177,41 +174,30 @@ module Hirb
|
|
177
174
|
end
|
178
175
|
|
179
176
|
#:stopdoc:
|
180
|
-
def enable_output_method
|
181
|
-
if
|
182
|
-
@output_method =
|
183
|
-
|
177
|
+
def enable_output_method
|
178
|
+
if defined? Ripl
|
179
|
+
@output_method = true
|
180
|
+
require 'ripl/hirb'
|
181
|
+
elsif defined? IRB
|
182
|
+
@output_method = true
|
183
|
+
::IRB::Irb.class_eval do
|
184
|
+
alias_method :non_hirb_view_output, :output_value
|
185
|
+
def output_value #:nodoc:
|
186
|
+
Hirb::View.view_or_page_output(@context.last_value) || non_hirb_view_output
|
187
|
+
end
|
188
|
+
end
|
184
189
|
end
|
185
190
|
end
|
186
191
|
|
187
|
-
def
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
alias_method :#{klass_method}, :non_hirb_view_output
|
192
|
-
end
|
193
|
-
]
|
192
|
+
def disable_output_method
|
193
|
+
if defined?(IRB) && !defined? Ripl
|
194
|
+
::IRB::Irb.send :alias_method, :output_value, :non_hirb_view_output
|
195
|
+
end
|
194
196
|
@output_method = nil
|
195
197
|
end
|
196
198
|
|
197
|
-
def
|
198
|
-
|
199
|
-
eval %[
|
200
|
-
::#{klass}.class_eval do
|
201
|
-
alias_method :non_hirb_view_output, :#{klass_method}
|
202
|
-
if '#{klass}' == "IRB::Irb"
|
203
|
-
def #{klass_method} #:nodoc:
|
204
|
-
Hirb::View.view_output(@context.last_value) || Hirb::View.page_output(@context.last_value.inspect, true) ||
|
205
|
-
non_hirb_view_output
|
206
|
-
end
|
207
|
-
else
|
208
|
-
def #{klass_method}(output_string) #:nodoc:
|
209
|
-
Hirb::View.view_output(output_string) || Hirb::View.page_output(output_string.inspect, true) ||
|
210
|
-
non_hirb_view_output(output_string)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
]
|
199
|
+
def view_or_page_output(str)
|
200
|
+
view_output(str) || page_output(str.inspect, true)
|
215
201
|
end
|
216
202
|
|
217
203
|
def render_output(output, options={})
|
data/lib/ripl/hirb.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Ripl::Hirb
|
2
|
+
def before_loop
|
3
|
+
super
|
4
|
+
require 'hirb'
|
5
|
+
Hirb.enable(Ripl.config[:hirb] || {}) unless Hirb::View.enabled?
|
6
|
+
end
|
7
|
+
|
8
|
+
def format_result(result)
|
9
|
+
return super if !Hirb::View.enabled?
|
10
|
+
Hirb::View.view_or_page_output(result) || super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Ripl::Shell.send :include, Ripl::Hirb
|
data/test/formatter_test.rb
CHANGED
@@ -53,24 +53,29 @@ describe "Formatter" do
|
|
53
53
|
describe "formatter methods:" do
|
54
54
|
before_all { eval "module ::Dooda; end" }
|
55
55
|
|
56
|
-
it "add_view sets formatter config" do
|
56
|
+
it "#add_view sets formatter config" do
|
57
57
|
@formatter = set_formatter
|
58
58
|
@formatter.add_view ::Dooda, :class=>"DoodaView"
|
59
59
|
@formatter.klass_config(::Dooda).should == {:class=>"DoodaView"}
|
60
60
|
end
|
61
61
|
|
62
|
-
it "add_view overwrites existing formatter config" do
|
62
|
+
it "#add_view overwrites existing formatter config" do
|
63
63
|
@formatter = set_formatter "Dooda"=>{:class=>"DoodaView"}
|
64
64
|
@formatter.add_view ::Dooda, :class=>"DoodaView2"
|
65
65
|
@formatter.klass_config(::Dooda).should == {:class=>"DoodaView2"}
|
66
66
|
end
|
67
67
|
|
68
|
-
it "parse_console_options passes all options except for formatter options into :options" do
|
68
|
+
it "#parse_console_options passes all options except for formatter options into :options" do
|
69
69
|
@formatter = set_formatter
|
70
70
|
options = {:class=>'blah', :method=>'blah', :output_method=>'blah', :blah=>'blah'}
|
71
71
|
expected_options = {:class=>'blah', :method=>'blah', :output_method=>'blah', :options=>{:blah=>'blah'}}
|
72
72
|
@formatter.parse_console_options(options).should == expected_options
|
73
73
|
end
|
74
|
+
|
75
|
+
it "#determine_output_class has exceptions for to_a" do
|
76
|
+
@formatter.determine_output_class(STDOUT).should == IO
|
77
|
+
@formatter.determine_output_class({:a=>1}).should == Hash
|
78
|
+
end
|
74
79
|
end
|
75
80
|
|
76
81
|
describe "format_output" do
|
@@ -124,7 +129,7 @@ describe "Formatter" do
|
|
124
129
|
require 'set'
|
125
130
|
view_output Set.new(['dude'])
|
126
131
|
end
|
127
|
-
|
132
|
+
|
128
133
|
it "formats with options option" do
|
129
134
|
eval "module ::Blahify; def self.render(*args); end; end"
|
130
135
|
enable_with_output "String"=>{:class=>"Blahify", :options=>{:fields=>%w{a b}}}
|
data/test/view_test.rb
CHANGED
@@ -92,13 +92,6 @@ describe "View" do
|
|
92
92
|
Hirb.config_files.include?('test_file').should == true
|
93
93
|
end
|
94
94
|
|
95
|
-
it "with output_method option realiases output_method" do
|
96
|
-
eval %[module ::Mini; extend self; def output(str); puts(str.inspect); end; end]
|
97
|
-
Hirb.enable :output_method=>"Mini.output", :output=>{"Symbol"=>{:output_method=>lambda {|e| e.to_s }}}
|
98
|
-
capture_stdout { ::Mini.output(:yoyo) }.should == "yoyo\n"
|
99
|
-
capture_stdout { ::Mini.output('blah') }.should == "\"blah\"\n"
|
100
|
-
end
|
101
|
-
|
102
95
|
it "with ignore_errors enable option" do
|
103
96
|
Hirb.enable :ignore_errors => true
|
104
97
|
View.stubs(:render_output).raises(Exception, "Ex mesg")
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hirb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 5
|
10
|
+
version: 0.3.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gabriel Horner
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-08 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/hirb/views/rails.rb
|
114
114
|
- lib/hirb/views.rb
|
115
115
|
- lib/hirb.rb
|
116
|
+
- lib/ripl/hirb.rb
|
116
117
|
- test/auto_table_test.rb
|
117
118
|
- test/console_test.rb
|
118
119
|
- test/dynamic_view_test.rb
|
@@ -158,12 +159,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
159
|
requirements:
|
159
160
|
- - ">="
|
160
161
|
- !ruby/object:Gem::Version
|
161
|
-
hash:
|
162
|
+
hash: 17
|
162
163
|
segments:
|
163
164
|
- 1
|
164
165
|
- 3
|
165
|
-
-
|
166
|
-
version: 1.3.
|
166
|
+
- 5
|
167
|
+
version: 1.3.5
|
167
168
|
requirements: []
|
168
169
|
|
169
170
|
rubyforge_project: tagaholic
|