Skip to content

Commit ee306e1

Browse files
author
Sven Riedel
committed
Introduce --all and prefer core docs by default
1 parent f2c6963 commit ee306e1

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

Changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
0.4.4
2+
- No longer display all found class/module documentation found. If core
3+
documentation is available, output only that, otherwise falls back to gem
4+
documentation. To show all found documentation use the --all command line
5+
paramter.
6+
17
0.4.3
28
- If multiple documentations are found that are all class documentations,
39
display all of these. This is useful in cases that gems extend core

README.rdoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ Bri is a Beautiful RI formatter.
2424

2525
= Usage
2626

27-
bri Array # looks up the class description of Array in the ri documentation
27+
bri Array # looks up the class description of Array in the ri documentation.
28+
# As of 0.4.4 this form will only output core documentation if
29+
# available, falling back to gem documentation if no core
30+
# documentation is found. This way you can look at the documentation
31+
# of core classes that gems love to money patch without having
32+
# to scroll back through your terminal.
33+
# If you really want to see everything there is, use --all:
34+
bri --all Array
2835

2936
bri Array.class_method # looks up the class method of the given class
3037

bin/bri

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ require 'optparse'
55
@options = {
66
:list_classes => false,
77
:list_methods => false,
8-
:list_names => false
8+
:list_names => false,
9+
:show_all => false
910
}
1011

1112
def parse_options
@@ -23,6 +24,7 @@ def parse_options
2324
opts.on( nil, "--methods", "List known methods" ) { |v| @options[:list_methods] = true }
2425
opts.on( "-l", "--list-names", "List known namespaces/methods" ) { |v| @options[:list_names] = true }
2526
opts.on( "-w", "--width [COLUMNS]", "Set the output width", Integer ) { |v| Bri.width = v.to_i - 8 }
27+
opts.on( "-a", "--all", "Output all documentation for the term. Prefers core documents otherwise") { |v| @options[:show_all] = true }
2628
opts.on_tail( "-h", "--help", "This help text" ) { puts opts; exit }
2729
end
2830
parser.parse!( ARGV )
@@ -43,5 +45,5 @@ elsif @options[:list_methods]
4345
elsif @options[:list_names]
4446
puts Bri.list_names
4547
else
46-
puts Bri.ri( ARGV[0] )
48+
puts Bri.ri( ARGV[0], show_all: @options[:show_all] )
4749
end

lib/bri.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@
1111
module Bri
1212
DEFAULT_WIDTH = 72
1313

14-
def self.ri( query )
14+
def self.ri( query, show_all: false )
1515
results = Bri::Matcher.new( query ).find
1616

1717
if results.size == 0
1818
"No matching results found"
1919
elsif results.size == 1
2020
results.first.to_s
2121
elsif results.all? { |r| r.is_a?(Bri::Match::Class) }
22-
results.map(&:to_s)
22+
if show_all
23+
results.map(&:to_s)
24+
else
25+
gem_docs, core_docs = results.partition { |r| r.origin =~ %r{gem\b} }
26+
27+
docs_to_output = core_docs.empty? ? gem_docs : core_docs
28+
docs_to_output.map(&:to_s)
29+
end
2330
else
2431
qualified_methods = results.map(&:full_name).sort
2532
ERB.new( Bri::Templates::MULTIPLE_CHOICES, nil, '<>' ).result( binding )

0 commit comments

Comments
 (0)