bri 0.2.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9c9a3a5911ab72b9546ab330dd5ee4513526deaecb4e508b818cef6f28b03283
4
+ data.tar.gz: 52dd0d1b13b6e74b54efebb4364ff56619776db6a8348f6ca8ab8aab67231fbf
5
+ SHA512:
6
+ metadata.gz: 548798d2184a8c2f6543d7164fafcee5ee2699ffee6547aa16a982387aea81307755c5b9bef95cf667b3d80614f3d2bf8f18a21fe727c14f593a1207f6163f02
7
+ data.tar.gz: 1836149121859a7d8b66a19dbbd5c0b18b536c3c4af440b6e7c1c5bac298fd40903ecd240a6cdb9bf46fb8f02914378bbf0ecb68fe024b030c0fc5d848496f3a
data/Changelog CHANGED
@@ -1,3 +1,13 @@
1
+ 0.4.1
2
+ - Modernize and refactor code
3
+ - Show extends of classes in rendered documentation
4
+ - Show superclass of classes in rendered documentation
5
+
6
+ 0.4.0
7
+ - Update gems to their current versions
8
+ - Require ruby 2.6 or later
9
+ - Fix code and specs to work with current rspec and rdoc
10
+
1
11
  0.2.1
2
12
  - Show origin of class/method in description output
3
13
  - Better textflow within paragraphs by ignoring the original newlines
@@ -30,8 +30,8 @@ Bri is a Beautiful RI formatter.
30
30
  # anywhere in the method name
31
31
 
32
32
  = Requirements
33
- * Ruby 1.9.2
34
- * rdoc 3.5.3 and above
33
+ * Ruby 2.6 or later
34
+ * rdoc 6.1 or later
35
35
  * term-ansicolor
36
36
 
37
37
 
data/TODO CHANGED
@@ -3,3 +3,7 @@
3
3
  a line wrap occurs
4
4
  - Refactor the convoluted rendering of lists and list items
5
5
  - Detect ansi capabilities and use what is possible with graceful degradation?
6
+ - Potentially try to detect method references in documentation prose and
7
+ highlight these (e.g. Object#send and Object.new)
8
+ - Add display of in_files
9
+ - Add display of module constant aliases
data/lib/bri.rb CHANGED
@@ -43,21 +43,21 @@ module Bri
43
43
  elsif results.size == 1
44
44
  results.first.to_s
45
45
  else
46
- qualified_methods = results.collect{ |result| result.full_name }.sort
47
46
  ERB.new( Bri::Templates::MULTIPLE_CHOICES, nil, '<>' ).result( binding )
48
47
  end
49
48
  end
50
49
 
51
50
  def self.width
52
- return @@width if defined?( @@width )
51
+ return @width if instance_variable_defined?( :@width )
52
+
53
53
  base_width = ENV['COLUMNS'].to_i
54
54
  base_width = 80 if base_width == 0
55
55
 
56
- @@width ||= [ base_width - 8, 1 ].max
56
+ @width ||= [ base_width - 8, 1 ].max
57
57
  end
58
58
 
59
59
  def self.width=( width )
60
- @@width = [ width, 1 ].max
60
+ @width = [ width, 1 ].max
61
61
  end
62
62
 
63
63
  def self.list_classes
@@ -9,35 +9,31 @@ module Bri
9
9
  attr_reader :stores
10
10
 
11
11
  def classes
12
- @stores.collect { |store| store.modules }.flatten.uniq.sort
12
+ stores.flat_map(&:module_names).uniq.sort
13
13
  end
14
14
 
15
15
  def class_methods
16
- Bri::Mall.instance.stores.map do |store|
16
+ stores.flat_map do |store|
17
17
  store.class_methods.map do |klass, methods|
18
18
  methods.map { |method| "#{klass}.#{method}" }
19
19
  end
20
- end.flatten.uniq
20
+ end.uniq
21
21
  end
22
22
 
23
23
  def instance_methods
24
- Bri::Mall.instance.stores.map do |store|
24
+ stores.flat_map do |store|
25
25
  store.instance_methods.map do |klass, methods|
26
26
  methods.map { |method| "#{klass}##{method}" }
27
27
  end
28
- end.flatten.uniq
28
+ end.uniq
29
29
  end
30
30
 
31
31
  private
32
32
  def initialize
33
- @stores = []
34
-
35
33
  # We want: system, site, home and gem documentation
36
- RDoc::RI::Paths.each( true, true, true, true ) do |path, type|
37
- @stores << RDoc::RI::Store.new( path, type ).
38
- tap { |store| store.load_cache }
39
- end
34
+ @stores = RDoc::RI::Paths.each( true, true, true, true ).each_with_object( [] ) do |(path, type), stores|
35
+ stores << RDoc::Store.new( path, type ).tap { |store| store.load_cache }
36
+ end
40
37
  end
41
-
42
38
  end
43
39
  end
@@ -8,7 +8,7 @@ module Bri
8
8
 
9
9
  private
10
10
  def build_description( source )
11
- source.collect { |element| Bri::Renderer.render element }
11
+ source.map { |element| Bri::Renderer.render( element ) }
12
12
  end
13
13
  end
14
14
  end
@@ -7,28 +7,28 @@ module Bri
7
7
  include Bri::Templates::Helpers
8
8
  TEMPLATE = Bri::Templates::CLASS_DESCRIPTION
9
9
 
10
- attr_reader :type, :name, :description_paragraphs
11
- attr_reader :includes, :constants, :class_methods, :instance_methods
12
- attr_reader :attributes, :origin
10
+ attr_reader :type, :name, :description_paragraphs,
11
+ :includes, :extends, :constants, :class_methods,
12
+ :instance_methods, :attributes, :origin
13
13
 
14
14
  def initialize( rdoc_result, store = nil )
15
- @type = rdoc_result.type
16
- @name = rdoc_result.full_name
17
- @description_paragraphs = build_description( rdoc_result.comment.parts )
18
- @includes = rdoc_result.includes.collect { |i| i.full_name }
19
- @constants = rdoc_result.constants.collect do |c|
20
- c.value ? "#{c.name} = #{c.value}" : c.name
21
- end
22
- @attributes = rdoc_result.attributes.collect { |a| "#{a.name} (#{a.rw})" }
23
-
24
15
  class_methods, instance_methods = rdoc_result.method_list.
25
16
  select {|m| m.visibility == :public }.
26
17
  partition { |m| m.singleton }
27
- @class_methods = class_methods.collect { |m| m.name }
28
- @instance_methods = instance_methods.collect { |m| m.name }
29
- @origin = store ? store.friendly_path : nil
18
+ @type = rdoc_result.type
19
+ @name = "#{rdoc_result.full_name}"
20
+ @name << " < #{rdoc_result.superclass}" if @type == "class" && rdoc_result.superclass
21
+ @description_paragraphs = build_description( rdoc_result.comment.parts )
22
+ @includes = rdoc_result.includes.map(&:full_name)
23
+ @extends = rdoc_result.extends.map(&:full_name)
24
+ @attributes = rdoc_result.attributes.map { |a| "#{a.name} (#{a.rw})" }
25
+ @class_methods = class_methods.map(&:name)
26
+ @instance_methods = instance_methods.map(&:name)
27
+ @origin = store&.friendly_path
28
+ @constants = rdoc_result.constants.map do |c|
29
+ c.value ? "#{c.name} = #{c.value}" : c.name
30
+ end
30
31
  end
31
-
32
32
  end
33
33
  end
34
34
  end
@@ -8,11 +8,11 @@ module Bri
8
8
 
9
9
  def initialize( rdoc_method, store = nil )
10
10
  @full_name = rdoc_method.full_name
11
- @call_syntaxes = rdoc_method.arglists.split( "\n" ).
12
- map { |e| " " + e }.
11
+ @call_syntaxes = rdoc_method.arglists.lines( chomp: true ).
12
+ map { |e| e.prepend( " " ) }.
13
13
  join( "\n" ) + "\n" rescue ''
14
14
  @description_paragraphs = build_description( rdoc_method.comment.parts )
15
- @origin = store ? store.friendly_path : nil
15
+ @origin = store&.friendly_path
16
16
  end
17
17
  end
18
18
  end
@@ -3,48 +3,52 @@ require 'strscan'
3
3
  module Bri
4
4
  module Renderer
5
5
  INDENT = ' ' * 2
6
- ALPHABET = ('a'..'z').to_a
6
+ INDENT_WIDTH = 2
7
+ LOWER_ALPHABET = ('a'..'z').to_a.map { |char| "#{char}." }.freeze
8
+ UPPER_ALPHABET = ('A'..'Z').to_a.map { |char| "#{char}." }.freeze
7
9
 
8
10
  def self.render( element, width = Bri.width, alignment_width = 0 )
9
- # STDERR.puts "Rendering #{element.inspect}"
10
11
  case element
11
12
  when RDoc::Markup::Verbatim
12
13
  text = extract_text( element, width )
13
14
  styled_text = replace_markup( text )
14
- indent( styled_text ) + "\n"
15
+ "#{indent( styled_text )}\n"
15
16
 
16
17
  when RDoc::Markup::List
17
- item_width = width - INDENT.length
18
+ item_width = width - INDENT_WIDTH
18
19
  case element.type
19
20
  when :BULLET
20
- rendered_items = element.items.collect { |item| render item, item_width }
21
+ rendered_items = element.items.map { |item| render( item, item_width ) }
21
22
  rendered_items.map! { |item| item.gsub( /\n/, "\n#{INDENT}" ) }
22
- rendered_items.map! { |item| ' *' + item }
23
+ rendered_items.map! { |item| item.prepend( ' *' ) }
23
24
 
24
25
  when :NUMBER
25
- i = 0
26
- rendered_items = element.items.collect { |item| render item, item_width }
26
+ rendered_items = element.items.map { |item| render( item, item_width ) }
27
27
  rendered_items.map! { |item| item.gsub( /\n/, "\n#{INDENT}" ) }
28
- rendered_items.map! { |item| i+=1; sprintf "%d.%s", i, item }
28
+ rendered_items.map!.with_index( 1 ) { |item, i| item.prepend( "#{i}." ) }
29
29
 
30
30
  when :LALPHA
31
- i = -1
32
- rendered_items = element.items.collect { |item| render item, item_width }
31
+ rendered_items = element.items.map { |item| render( item, item_width ) }
33
32
  rendered_items.map! { |item| item.gsub( /\n/, "\n#{INDENT}" ) }
34
- rendered_items.map! { |item| i+=1; sprintf "%s.%s", ALPHABET[i], item }
33
+ rendered_items.map!.with_index { |item, i| item.prepend( LOWER_ALPHABET[i] ) }
34
+
35
+ when :UALPHA
36
+ rendered_items = element.items.map { |item| render( item, item_width ) }
37
+ rendered_items.map! { |item| item.gsub( /\n/, "\n#{INDENT}" ) }
38
+ rendered_items.map!.with_index { |item, index| item.prepend( UPPER_ALPHABET[i] ) }
35
39
 
36
40
  when :LABEL
37
41
  # do nothing
38
- rendered_items = element.items.collect { |item| render item, item_width }
42
+ rendered_items = element.items.map { |item| render( item, item_width ) }
39
43
  rendered_items.map! { |item| item.gsub( /\n/, "\n#{INDENT}" ) }
40
44
 
41
45
  when :NOTE
42
- alignment_width = element.items.collect { |item| item.label.size }.max + 1
43
- rendered_items = element.items.collect { |item| render item, item_width, alignment_width }
46
+ alignment_width = element.items.flat_map(&:label).map(&:size).max + 1
47
+ rendered_items = element.items.map { |item| render( item, item_width, alignment_width ) }
44
48
  rendered_items.map! { |item| item.gsub( /\n/, "\n#{INDENT}" ) }
45
49
  end
46
50
 
47
- rendered_items.join( "\n\n" ) + "\n"
51
+ "#{rendered_items.join( "\n\n" )}\n"
48
52
 
49
53
  else
50
54
  text = extract_text( element, width, alignment_width )
@@ -56,64 +60,81 @@ module Bri
56
60
 
57
61
  def self.extract_text( element, width, label_alignment_width = 0, conserve_newlines = false )
58
62
  text = case element
59
- when RDoc::Markup::Paragraph
63
+ when RDoc::Markup::Paragraph
60
64
  join_char = conserve_newlines ? "\n" : " "
61
- element.parts.join( join_char )
65
+ element.parts.map(&:strip).join( join_char )
66
+
62
67
  when RDoc::Markup::BlankLine
63
68
  ""
69
+
64
70
  when RDoc::Markup::Rule
65
71
  "-" * width
72
+
66
73
  when RDoc::Markup::Verbatim
67
- element.text
74
+ element.parts.map { |part| part.prepend( " " ) }.join
75
+
68
76
  when RDoc::Markup::Heading
69
77
  "<h>#{element.text}</h>"
78
+
70
79
  when RDoc::Markup::ListItem
71
- parts = element.parts.collect { |part| extract_text part, width, 0, true }.join
72
- element.label ? sprintf( "%*s %s", -label_alignment_width, "#{element.label}:", parts ) : parts
80
+ parts = element.parts.map { |part| extract_text( part, width, 0, true ) }.join
81
+
82
+ if element.label
83
+ labels = element.label.map { |l| "#{l}:" }.join("\n")
84
+ sprintf( "%*s %s", -label_alignment_width, labels, parts )
85
+ else
86
+ parts
87
+ end
88
+
73
89
  when RDoc::Markup::List
74
- render( element, width - INDENT.length )
90
+ render( element, width - INDENT_WIDTH )
91
+
92
+ when RDoc::Markup::Document
93
+ element.parts.
94
+ map { |part| extract_text( part, width, label_alignment_width, conserve_newlines ) }.
95
+ join
75
96
  else
76
97
  raise "Don't know how to handle type #{element.class}: #{element.inspect}"
77
98
  end
78
- text + "\n"
99
+ text << "\n"
79
100
  end
80
101
 
81
102
  def self.replace_markup( text )
82
- text.gsub!( /(?<!\\)<(?:tt|code)>/, Term::ANSIColor::cyan )
83
- text.gsub!( /(?<!\\)<\/(?:tt|code)>/, Term::ANSIColor::reset )
103
+ text.gsub!( /(?<!\\)<(?:tt|code)>/, Term::ANSIColor.cyan )
104
+ text.gsub!( /(?<!\\)<\/(?:tt|code)>/, Term::ANSIColor.reset )
84
105
 
85
- text.gsub!( /(?<!\\)<b>/, Term::ANSIColor::bold )
86
- text.gsub!( /(?<!\\)<\/b>/, Term::ANSIColor::reset )
106
+ text.gsub!( /(?<!\\)<b>/, Term::ANSIColor.bold )
107
+ text.gsub!( /(?<!\\)<\/b>/, Term::ANSIColor.reset )
87
108
 
88
- text.gsub!( /(?<!\\)<(?:em|i)>/, Term::ANSIColor::yellow )
89
- text.gsub!( /(?<!\\)<\/(?:em|i)>/, Term::ANSIColor::reset )
109
+ text.gsub!( /(?<!\\)<(?:em|i)>/, Term::ANSIColor.yellow )
110
+ text.gsub!( /(?<!\\)<\/(?:em|i)>/, Term::ANSIColor.reset )
90
111
 
91
- text.gsub!( "<h>", Term::ANSIColor::green )
92
- text.gsub!( "</h>", Term::ANSIColor::reset )
112
+ text.gsub!( "<h>", Term::ANSIColor.green )
113
+ text.gsub!( "</h>", Term::ANSIColor.reset )
93
114
 
94
115
  text.gsub!( "\\<", "<" )
95
116
 
96
117
  text.gsub!( /(^|\s)\*(.*?[a-zA-Z0-9]+.*?)\*/,
97
- "\\1#{Term::ANSIColor::bold}\\2#{Term::ANSIColor::reset}" )
118
+ "\\1#{Term::ANSIColor.bold}\\2#{Term::ANSIColor.reset}" )
98
119
  text.gsub!( /(^|\s)\+(.*?[a-zA-Z0-9]+.*?)\+/,
99
- "\\1#{Term::ANSIColor::cyan}\\2#{Term::ANSIColor::reset}" )
120
+ "\\1#{Term::ANSIColor.cyan}\\2#{Term::ANSIColor.reset}" )
100
121
  text.gsub!( /(^|\s)_(.*?[a-zA-Z0-9]+.*?)_/,
101
- "\\1#{Term::ANSIColor::yellow}\\2#{Term::ANSIColor::reset}" )
122
+ "\\1#{Term::ANSIColor.yellow}\\2#{Term::ANSIColor.reset}" )
102
123
 
103
124
  text.gsub!( %r{\b((?:https?|ftp)://[-\w.?%&=/]+)\b},
104
- "#{Term::ANSIColor::underline}\\1#{Term::ANSIColor::reset}" )
125
+ "#{Term::ANSIColor.underline}\\1#{Term::ANSIColor.reset}" )
105
126
 
106
127
  text.gsub!( %r{\b(mailto:[-\w.%]+@[-\w.]+)\b},
107
- "#{Term::ANSIColor::underline}\\1#{Term::ANSIColor::reset}" )
128
+ "#{Term::ANSIColor.underline}\\1#{Term::ANSIColor.reset}" )
108
129
 
109
130
  text.gsub!( %r{\b((?<!:\/\/)www.[-\w.?%&=]+)\b},
110
- "#{Term::ANSIColor::underline}\\1#{Term::ANSIColor::reset}" )
131
+ "#{Term::ANSIColor.underline}\\1#{Term::ANSIColor.reset}" )
111
132
 
112
133
  text.gsub!( %r{\blink:(.*?)(\s|$)},
113
- "#{Term::ANSIColor::underline}\\1#{Term::ANSIColor::reset}\\2" )
134
+ "#{Term::ANSIColor.underline}\\1#{Term::ANSIColor.reset}\\2" )
114
135
 
115
136
  text.gsub!( %r{\{(.*?)\}\[(.*?)\]}, "\\1 (\\2)" )
116
- text.gsub!( %r{\[(#{Regexp.escape( Term::ANSIColor::underline )}.*?#{Regexp.escape( Term::ANSIColor::reset )})\]},
137
+ text.gsub!( %r{\[(#{Regexp.escape( Term::ANSIColor.underline )}.*?#{Regexp.escape( Term::ANSIColor.reset )})\]},
117
138
  " (\\1)" )
118
139
  text
119
140
  end
@@ -127,7 +148,7 @@ module Bri
127
148
  end
128
149
 
129
150
  def self.wrap_to_width( styled_text, width )
130
- styled_text.split( "\n" ).collect { |row| wrap_row row, width }.join
151
+ styled_text.split( "\n" ).map { |row| wrap_row( row, width ) }.join
131
152
  end
132
153
 
133
154
  def self.wrap_row( physical_row, width )
@@ -146,6 +167,7 @@ module Bri
146
167
  logical_row = ''
147
168
  printable_row_length = 0
148
169
  end
170
+
149
171
  logical_row << token
150
172
  printable_row_length += printable_token_length
151
173
 
@@ -153,11 +175,12 @@ module Bri
153
175
  logical_row << token
154
176
  printable_row_length += token.length
155
177
  end
178
+
156
179
  output_text << logical_row << "\n"
157
180
  end
158
181
 
159
182
  def self.indent( text )
160
- text.split( "\n" ).collect { |row| "#{INDENT}#{row}" }.join("\n" )
183
+ text.split( "\n" ).map { |row| "#{INDENT}#{row}" }.join("\n" )
161
184
  end
162
185
  end
163
186
  end
@@ -1,14 +1,12 @@
1
1
  module Bri
2
2
  module Search
3
3
  class Class < Base
4
-
5
4
  def search( type = :fully_qualified )
6
5
  # NOTE: classes are only searched as fully qualified for the time being
7
6
  # FIXME: What do we do if more than one store defines the same class?
8
- store = Bri::Mall.instance.stores.detect { |s| s.modules.include? @term }
7
+ store = Bri::Mall.instance.stores.detect { |s| s.module_names.include?( @term ) }
9
8
  @matches << Bri::Match::Class.new( store.load_class( @term ), store ) if store
10
9
  end
11
-
12
10
  end
13
11
  end
14
12
  end
@@ -8,6 +8,7 @@ module Bri
8
8
 
9
9
  def method_rdoc( store, klass = @class_term, method = @method_term )
10
10
  store.load_method( klass, method )
11
+
11
12
  rescue Errno::ENOENT
12
13
  nil
13
14
  end
@@ -7,7 +7,8 @@ module Bri
7
7
  end
8
8
 
9
9
  def method_rdoc( store, klass = @class_term, method = @method_term )
10
- store.load_method( klass, "#" + method )
10
+ store.load_method( klass, "##{method}" )
11
+
11
12
  rescue Errno::ENOENT
12
13
  nil
13
14
  end
@@ -7,11 +7,11 @@ module Bri
7
7
  super
8
8
  @class_term, @method_term = term.split( /[\.#]/, 2 )
9
9
 
10
- if @class_term !~ /^[A-Z]/ && @method_term.nil?
10
+ if @class_term !~ /^[A-Z]/ && !@method_term
11
11
  @method_term, @class_term = @class_term, @method_term
12
12
  end
13
13
 
14
- @class_term = nil if @class_term == ""
14
+ @class_term = nil if @class_term&.empty?
15
15
  end
16
16
 
17
17
  def search( type = :fully_qualified )
@@ -38,17 +38,18 @@ module Bri
38
38
  end
39
39
 
40
40
  def classes_with_method( store, method )
41
- store_methods( store ).select { |klass, methods| methods.include? method }.keys
41
+ store_methods( store ).select do |_klass, methods|
42
+ methods.include?( method )
43
+ end.keys
42
44
  end
43
45
 
44
46
  def candidates_from_method_re( store, method_re )
45
- candidates = {}
46
- store_methods( store ).each do |klass, methods|
47
+ store_methods( store ).each_with_object( {} ) do |(klass, methods), candidates|
47
48
  matching_methods = methods.grep( method_re )
48
49
  next if matching_methods.empty?
50
+
49
51
  candidates[klass] = matching_methods
50
52
  end
51
- candidates
52
53
  end
53
54
 
54
55
 
@@ -64,9 +65,9 @@ module Bri
64
65
  end
65
66
 
66
67
  def unqualified_search
67
- [ /^#{Regexp.escape @method_term}$/,
68
- /^#{Regexp.escape @method_term}/,
69
- /#{Regexp.escape @method_term}/ ].each do |method_re|
68
+ [ /^#{Regexp.escape( @method_term )}$/,
69
+ /^#{Regexp.escape( @method_term )}/,
70
+ /#{Regexp.escape( @method_term )}/ ].each do |method_re|
70
71
  unqualified_search_worker( method_re )
71
72
  break unless @matches.empty?
72
73
  end
@@ -84,7 +85,6 @@ module Bri
84
85
  end
85
86
  end
86
87
  end
87
-
88
88
  end
89
89
  end
90
90
  end
@@ -1,5 +1,7 @@
1
1
  module Bri
2
2
  module Templates
3
+ RULE_CHARACTER = '-'.freeze
4
+
3
5
  MULTIPLE_CHOICES =<<-EOT
4
6
  <%= Bri::Templates::Helpers.hrule( "Multiple choices:" ) %>
5
7
 
@@ -25,6 +27,12 @@ module Bri
25
27
  <%= Bri::Renderer.wrap_list( includes.sort ) %>
26
28
 
27
29
 
30
+ <% end %>
31
+ <% if !extends.empty? %>
32
+ <%= section_header( "Extends:" ) %>
33
+ <%= Bri::Renderer.wrap_list( extends.sort ) %>
34
+
35
+
28
36
  <% end %>
29
37
  <% if !constants.empty? %>
30
38
  <%= section_header( "Constants:" ) %>
@@ -68,12 +76,13 @@ module Bri
68
76
 
69
77
  module Helpers
70
78
  def hrule( text = '', width = Bri.width )
71
- if text == ''
72
- '-' * width + "\n"
73
- else
74
- text = " " + text if text != ''
75
- ( '-' * [ ( width - text.length ), 1 ].max ) + Term::ANSIColor::bold( text ) + "\n"
76
- end
79
+ text.prepend( " " ) unless text.empty?
80
+
81
+ rule_length = width - text.length
82
+ rule_length = 1 if rule_length < 1
83
+
84
+ rule = RULE_CHARACTER * rule_length
85
+ "#{rule}#{Term::ANSIColor::bold( text )}\n"
77
86
  end
78
87
  module_function :hrule
79
88
 
@@ -83,7 +92,7 @@ module Bri
83
92
  end
84
93
 
85
94
  def section_header( text )
86
- Term::ANSIColor::green + Term::ANSIColor::underline + text + Term::ANSIColor::reset + "\n"
95
+ "#{Term::ANSIColor.green}#{Term::ANSIColor.underline}#{text}#{Term::ANSIColor.reset}\n"
87
96
  end
88
97
  module_function :section_header
89
98
  end
@@ -37,17 +37,17 @@ describe Bri::Match::Class do
37
37
 
38
38
  describe "#name" do
39
39
  it "should contain the name of a class" do
40
- empty_class.name.should == "BriDummySpecClassEmpty"
40
+ empty_class.name.should == "BriDummySpecClassEmpty < Object"
41
41
  end
42
42
 
43
43
  it "should contain the fully qualified name of a namespaced class" do
44
- namespaced_class.name.should == "BriDummySpec::Class"
44
+ namespaced_class.name.should == "BriDummySpec::Class < Object"
45
45
  end
46
46
  end
47
47
 
48
48
  describe "#description_paragraphs" do
49
49
  it "should be empty for an undocumented class" do
50
- empty_class.description_paragraphs.should be_empty
50
+ empty_class.description_paragraphs.should == [ '' ]
51
51
  end
52
52
 
53
53
  it "should contain rendered text for a documented class" do
@@ -6,11 +6,11 @@ describe Bri::Match::Method do
6
6
  end
7
7
 
8
8
  let( :fake_description ) do
9
- mock( RDoc::Markup::Document, :parts => [ fake_paragraph ] )
9
+ double( RDoc::Markup::Document, :parts => [ fake_paragraph ] )
10
10
  end
11
11
 
12
12
  let( :rdoc_method ) do
13
- mock( RDoc::AnyMethod, :full_name => "This::IS::My.full_name",
13
+ double( RDoc::AnyMethod, :full_name => "This::IS::My.full_name",
14
14
  :arglists => "First\nSecond\nThird",
15
15
  :comment => fake_description )
16
16
  end
@@ -75,14 +75,14 @@ describe Bri::Renderer do
75
75
  end
76
76
 
77
77
  it "should start second lines of a list item with the same left alignment as the first list items content" do
78
- subject.should =~ /\n \* First item in a bulleted list\n With a second line\n/
78
+ subject.should =~ /\n \* First item in a bulleted list(?:\s*?)\n With a second line\n/
79
79
  end
80
80
 
81
81
  context "contained verbatim text" do
82
82
  subject { render_description_for_method( "list_containing_verbatim_text" ) }
83
83
 
84
84
  it "should correctly display verbatim text" do
85
- subject.should =~ /\n Containing verbatim text\n/
85
+ subject.should =~ /\n Containing verbatim text\n/
86
86
  end
87
87
  end
88
88
 
@@ -3,26 +3,26 @@ require 'spec_helper'
3
3
  describe Bri::Search::ClassMethod do
4
4
  context "the searches" do
5
5
  let( :paragraph ) { RDoc::Markup::Paragraph.new( "Foo Description" ) }
6
- let( :document ) { mock( RDoc::Markup::Document, :parts => [ paragraph ] ) }
7
- let( :rdoc_method ) { mock( RDoc::AnyMethod, :full_name => "Foo",
6
+ let( :document ) { double( RDoc::Markup::Document, :parts => [ paragraph ] ) }
7
+ let( :rdoc_method ) { double( RDoc::AnyMethod, :full_name => "Foo",
8
8
  :arglists => "",
9
9
  :comment => document ) }
10
10
  before( :each ) do
11
- store_one = mock( RDoc::RI::Store, :load_cache => true,
11
+ store_one = double( RDoc::RI::Store, :load_cache => true,
12
12
  :load_class => true,
13
13
  :load_method => rdoc_method,
14
14
  :friendly_path => "ruby core",
15
15
  :modules => %w{ ClassThree },
16
16
  :class_methods => { "ClassThree" => [ "method" ] } )
17
- store_two = mock( RDoc::RI::Store, :load_cache => true,
17
+ store_two = double( RDoc::RI::Store, :load_cache => true,
18
18
  :load_class => true,
19
19
  :load_method => rdoc_method,
20
20
  :friendly_path => "ruby core",
21
21
  :modules => %w{ ClassOne ClassTwo },
22
22
  :class_methods => { "ClassOne" => [ "method" ],
23
23
  "ClassTwo" => [ "method", "my_other_method" ] } )
24
- Bri::Mall.instance.stub!( :stores => [ store_one, store_two ] )
25
- Bri::Match::Class.stub!( :new ).and_return( mock( Bri::Match::Class ) )
24
+ allow(Bri::Mall.instance).to receive( :stores ).and_return( [ store_one, store_two ] )
25
+ allow(Bri::Match::Class).to receive( :new ).and_return( double( Bri::Match::Class ) )
26
26
  end
27
27
 
28
28
  describe "a fully qualified search" do
@@ -124,7 +124,7 @@ describe Bri::Search::ClassMethod do
124
124
  search_instance = Bri::Search::ClassMethod.new( ".bri_dummy_spec_singleton_method" )
125
125
  search_instance.search( :partially_qualified )
126
126
  search_instance.matches.should_not be_empty
127
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_singleton_method" }.should be_true
127
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_singleton_method" }.should be(true)
128
128
  end
129
129
  end
130
130
 
@@ -133,8 +133,8 @@ describe Bri::Search::ClassMethod do
133
133
  search_instance = Bri::Search::ClassMethod.new( ".bri_dummy_spec_second_singleton_method" )
134
134
  search_instance.search( :partially_qualified )
135
135
  search_instance.matches.should_not be_empty
136
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_second_singleton_method" }.should be_true
137
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClassTwo::bri_dummy_spec_second_singleton_method" }.should be_true
136
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_second_singleton_method" }.should be(true)
137
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClassTwo::bri_dummy_spec_second_singleton_method" }.should be(true)
138
138
  end
139
139
  end
140
140
  end
@@ -153,7 +153,7 @@ describe Bri::Search::ClassMethod do
153
153
  search_instance = Bri::Search::ClassMethod.new( "bri_dummy_spec_singleton_method" )
154
154
  search_instance.search( :unqualified )
155
155
  search_instance.matches.should_not be_empty
156
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_singleton_method" }.should be_true
156
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_singleton_method" }.should be(true)
157
157
  end
158
158
  end
159
159
 
@@ -162,9 +162,9 @@ describe Bri::Search::ClassMethod do
162
162
  search_instance = Bri::Search::ClassMethod.new( "bri_dummy_spec" )
163
163
  search_instance.search( :unqualified )
164
164
  search_instance.matches.should_not be_empty
165
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_singleton_method" }.should be_true
166
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_second_singleton_method" }.should be_true
167
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClassTwo::bri_dummy_spec_second_singleton_method" }.should be_true
165
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_singleton_method" }.should be(true)
166
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass::bri_dummy_spec_second_singleton_method" }.should be(true)
167
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClassTwo::bri_dummy_spec_second_singleton_method" }.should be(true)
168
168
  end
169
169
  end
170
170
  end
@@ -13,16 +13,16 @@ describe Bri::Search::Class do
13
13
  describe "#search" do
14
14
  context "basic functionality" do
15
15
  before( :each ) do
16
- store_one = mock( RDoc::RI::Store, :load_cache => true,
17
- :load_class => true,
18
- :friendly_path => "ruby core",
19
- :modules => %w{ ClassThree } )
20
- store_two = mock( RDoc::RI::Store, :load_cache => true,
21
- :load_class => true,
22
- :friendly_path => "ruby core",
23
- :modules => %w{ ClassOne ClassTwo } )
24
- Bri::Mall.instance.stub!( :stores => [ store_one, store_two ] )
25
- Bri::Match::Class.stub!( :new ).and_return( mock( Bri::Match::Class ) )
16
+ store_one = double( RDoc::Store, :load_cache => true,
17
+ :load_class => true,
18
+ :friendly_path => "ruby core",
19
+ :module_names => %w{ ClassThree } )
20
+ store_two = double( RDoc::Store, :load_cache => true,
21
+ :load_class => true,
22
+ :friendly_path => "ruby core",
23
+ :module_names => %w{ ClassOne ClassTwo } )
24
+ allow(Bri::Mall.instance).to receive( :stores ).and_return( [ store_one, store_two ] )
25
+ allow(Bri::Match::Class).to receive( :new ).and_return( double( Bri::Match::Class ) )
26
26
  end
27
27
 
28
28
  context "if there are no matching modules in any store" do
@@ -49,7 +49,7 @@ describe Bri::Search::Class do
49
49
  it "should have matches" do
50
50
  subject.search
51
51
  subject.matches.should_not be_empty
52
- subject.matches.any?{ |match| match.name == "BriDummySpecClass" }.should be_true
52
+ subject.matches.any?{ |match| match.name == "BriDummySpecClass < Object" }.should be(true)
53
53
  end
54
54
  end
55
55
 
@@ -58,10 +58,9 @@ describe Bri::Search::Class do
58
58
 
59
59
  it "should not have any matches" do
60
60
  subject.search
61
- subject.matches.any? { |match| match.name == "IAmQuiteCertainIDontExist" }.should be_false
61
+ subject.matches.any? { |match| match.name == "IAmQuiteCertainIDontExist" }.should be(false)
62
62
  end
63
63
  end
64
64
  end
65
-
66
65
  end
67
66
  end
@@ -3,26 +3,26 @@ require 'spec_helper'
3
3
  describe Bri::Search::InstanceMethod do
4
4
  context "the searches" do
5
5
  let( :paragraph ) { RDoc::Markup::Paragraph.new( "Foo Description" ) }
6
- let( :document ) { mock( RDoc::Markup::Document, :parts => [ paragraph ] ) }
7
- let( :rdoc_method ) { mock( RDoc::AnyMethod, :full_name => "Foo",
6
+ let( :document ) { double( RDoc::Markup::Document, :parts => [ paragraph ] ) }
7
+ let( :rdoc_method ) { double( RDoc::AnyMethod, :full_name => "Foo",
8
8
  :arglists => "",
9
9
  :comment => document ) }
10
10
  before( :each ) do
11
- store_one = mock( RDoc::RI::Store, :load_cache => true,
11
+ store_one = double( RDoc::RI::Store, :load_cache => true,
12
12
  :load_class => true,
13
13
  :load_method => rdoc_method,
14
14
  :friendly_path => "ruby core",
15
15
  :modules => %w{ ClassThree },
16
16
  :instance_methods => { "ClassThree" => [ "method" ] } )
17
- store_two = mock( RDoc::RI::Store, :load_cache => true,
17
+ store_two = double( RDoc::RI::Store, :load_cache => true,
18
18
  :load_class => true,
19
19
  :load_method => rdoc_method,
20
20
  :friendly_path => "ruby core",
21
21
  :modules => %w{ ClassOne ClassTwo },
22
22
  :instance_methods => { "ClassOne" => [ "method" ],
23
23
  "ClassTwo" => [ "method", "my_other_method" ] } )
24
- Bri::Mall.instance.stub!( :stores => [ store_one, store_two ] )
25
- Bri::Match::Class.stub!( :new ).and_return( mock( Bri::Match::Class ) )
24
+ allow(Bri::Mall.instance).to receive(:stores).and_return( [ store_one, store_two ] )
25
+ allow(Bri::Match::Class).to receive( :new ).and_return( double( Bri::Match::Class ) )
26
26
  end
27
27
 
28
28
  describe "a fully qualified search" do
@@ -124,7 +124,7 @@ describe Bri::Search::InstanceMethod do
124
124
  search_instance = Bri::Search::InstanceMethod.new( "#bri_dummy_spec_instance_method" )
125
125
  search_instance.search( :partially_qualified )
126
126
  search_instance.matches.should_not be_empty
127
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass#bri_dummy_spec_instance_method" }.should be_true
127
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass#bri_dummy_spec_instance_method" }.should be(true)
128
128
  end
129
129
  end
130
130
 
@@ -133,8 +133,8 @@ describe Bri::Search::InstanceMethod do
133
133
  search_instance = Bri::Search::InstanceMethod.new( "#bri_dummy_spec_instance_method_with_arguments" )
134
134
  search_instance.search( :partially_qualified )
135
135
  search_instance.matches.should_not be_empty
136
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass#bri_dummy_spec_instance_method_with_arguments" }.should be_true
137
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClassTwo#bri_dummy_spec_instance_method_with_arguments" }.should be_true
136
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass#bri_dummy_spec_instance_method_with_arguments" }.should be(true)
137
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClassTwo#bri_dummy_spec_instance_method_with_arguments" }.should be(true)
138
138
  end
139
139
  end
140
140
  end
@@ -153,7 +153,7 @@ describe Bri::Search::InstanceMethod do
153
153
  search_instance = Bri::Search::InstanceMethod.new( "bri_dummy_spec_instance_method" )
154
154
  search_instance.search( :unqualified )
155
155
  search_instance.matches.should_not be_empty
156
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass#bri_dummy_spec_instance_method" }.should be_true
156
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass#bri_dummy_spec_instance_method" }.should be(true)
157
157
  end
158
158
  end
159
159
 
@@ -162,10 +162,10 @@ describe Bri::Search::InstanceMethod do
162
162
  search_instance = Bri::Search::InstanceMethod.new( "bri_dummy_spec" )
163
163
  search_instance.search( :unqualified )
164
164
  search_instance.matches.should_not be_empty
165
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass#bri_dummy_spec_instance_method" }.should be_true
166
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass#bri_dummy_spec_instance_method_with_arguments" }.should be_true
167
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClassTwo#bri_dummy_spec_instance_method_with_arguments" }.should be_true
168
- search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass#bri_dummy_spec_instance_method_with_default_arguments" }.should be_true
165
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass#bri_dummy_spec_instance_method" }.should be(true)
166
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass#bri_dummy_spec_instance_method_with_arguments" }.should be(true)
167
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClassTwo#bri_dummy_spec_instance_method_with_arguments" }.should be(true)
168
+ search_instance.matches.any? { |match| match.full_name == "BriDummySpecClass#bri_dummy_spec_instance_method_with_default_arguments" }.should be(true)
169
169
  end
170
170
  end
171
171
  end
@@ -1,7 +1,22 @@
1
- spec_root = File.dirname( __FILE__ )
2
- require File.join( spec_root, '..', 'lib', 'bri.rb' )
1
+ require 'rspec/its'
2
+ require 'byebug'
3
+ require_relative '../lib/bri'
4
+
5
+ RSpec.configure do |config|
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.syntax = [ :should, :expect ]
8
+ end
9
+
10
+ config.expect_with :rspec do |expect|
11
+ expect.syntax = [ :should, :expect ]
12
+ end
13
+
14
+ config.order = :random
15
+ Kernel.srand config.seed
16
+ end
17
+
18
+ RSpec::Expectations.configuration.on_potential_false_positives = :nothing
3
19
 
4
20
  puts "Regenerating ri document cache"
5
- output_path = File.join( spec_root, 'ri' )
6
- class_file = File.join( spec_root, 'bri_dummy_spec_class.rb' )
21
+ class_file = File.join( __dir__, 'bri_dummy_spec_class.rb' )
7
22
  %x{rdoc --ri #{class_file}}
metadata CHANGED
@@ -1,100 +1,145 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: 0.4.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sven Riedel
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-05-20 00:00:00.000000000Z
11
+ date: 2011-05-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: term-ansicolor
16
- requirement: &10035380 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: 1.0.5
19
+ version: 1.7.1
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *10035380
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.1
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rdoc
27
- requirement: &10211940 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ~>
31
+ - - "~>"
31
32
  - !ruby/object:Gem::Version
32
- version: 3.5.2
33
+ version: 6.1.1
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *10211940
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 6.1.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.8.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.8.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
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'
36
83
  description: An alternative to the ri command
37
84
  email: sr@gimp.org
38
85
  executables:
39
86
  - bri
40
87
  extensions: []
41
88
  extra_rdoc_files:
42
- - README
89
+ - README.rdoc
43
90
  files:
44
- - README
45
- - TODO
46
91
  - Changelog
92
+ - README.rdoc
93
+ - TODO
47
94
  - bin/bri
48
95
  - lib/bri.rb
49
96
  - lib/bri/mall.rb
50
- - lib/bri/matcher.rb
51
97
  - lib/bri/match.rb
52
98
  - lib/bri/match/base.rb
53
99
  - lib/bri/match/class.rb
54
100
  - lib/bri/match/method.rb
101
+ - lib/bri/matcher.rb
102
+ - lib/bri/renderer.rb
55
103
  - lib/bri/search.rb
56
104
  - lib/bri/search/base.rb
57
105
  - lib/bri/search/class.rb
58
- - lib/bri/search/method.rb
59
106
  - lib/bri/search/class_method.rb
60
107
  - lib/bri/search/instance_method.rb
108
+ - lib/bri/search/method.rb
61
109
  - lib/bri/templates.rb
62
- - lib/bri/renderer.rb
63
- - spec/spec_helper.rb
64
110
  - spec/bri_dummy_spec_class.rb
65
111
  - spec/lib/bri/mall_spec.rb
66
- - spec/lib/bri/matcher_spec.rb
67
- - spec/lib/bri/renderer_spec.rb
68
112
  - spec/lib/bri/match/class_spec.rb
69
113
  - spec/lib/bri/match/method_spec.rb
70
- - spec/lib/bri/search/class_spec.rb
114
+ - spec/lib/bri/matcher_spec.rb
115
+ - spec/lib/bri/renderer_spec.rb
71
116
  - spec/lib/bri/search/class_method_spec.rb
117
+ - spec/lib/bri/search/class_spec.rb
72
118
  - spec/lib/bri/search/instance_method_spec.rb
73
119
  - spec/lib/bri/search/method_spec.rb
120
+ - spec/spec_helper.rb
74
121
  homepage: http://github.com/sriedel/bri
75
122
  licenses: []
123
+ metadata: {}
76
124
  post_install_message:
77
125
  rdoc_options:
78
- - --charset=UTF-8
126
+ - "--charset=UTF-8"
79
127
  require_paths:
80
128
  - lib
81
129
  required_ruby_version: !ruby/object:Gem::Requirement
82
- none: false
83
130
  requirements:
84
- - - ! '>='
131
+ - - ">="
85
132
  - !ruby/object:Gem::Version
86
- version: 1.9.2
133
+ version: 2.6.0
87
134
  required_rubygems_version: !ruby/object:Gem::Requirement
88
- none: false
89
135
  requirements:
90
- - - ! '>='
136
+ - - ">="
91
137
  - !ruby/object:Gem::Version
92
138
  version: '0'
93
139
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 1.8.2
140
+ rubygems_version: 3.0.3
96
141
  signing_key:
97
- specification_version: 3
142
+ specification_version: 4
98
143
  summary: Beautified RI in the spirit of fastri/qri. Unlike fastri, bri builds on top
99
144
  of the rdoc 2.x/3.x backend, only output and formatting is handled by bri
100
145
  test_files: []