Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

The ClassModule includes list now merges based on source file. Issue #21

  • Loading branch information...
commit b33e0860eec87b7eaba190dce17e1fd82d1660bd 1 parent 7e1e189
@drbrain drbrain authored
View
42 lib/rdoc/class_module.rb
@@ -243,7 +243,7 @@ def marshal_dump # :nodoc:
[const.name, parse(const.comment), const.file.absolute_name]
end,
includes.map do |incl|
- [incl.name, parse(incl.comment)]
+ [incl.name, parse(incl.comment), incl.file.absolute_name]
end,
method_types,
]
@@ -280,8 +280,9 @@ def marshal_load array # :nodoc:
const.record_location RDoc::TopLevel.new file
end
- array[7].each do |name, comment|
- add_include RDoc::Include.new(name, comment)
+ array[7].each do |name, comment, file|
+ incl = add_include RDoc::Include.new(name, comment)
+ incl.record_location RDoc::TopLevel.new file
end
array[8].each do |type, visibilities|
@@ -320,29 +321,15 @@ def merge class_module
@comment = document
end
- other_attrs = class_module.attributes.group_by { |attr| attr.file }
- my_attrs = attributes. group_by { |attr| attr.file }
-
- other_attrs.each do |file, attrs|
- next if my_attrs.include? file
-
- attrs.each do |attr|
- add_attribute attr
- end
+ merge_collections attributes, class_module.attributes do |const|
+ add_attribute const
end
- other_consts = class_module.constants.group_by { |const| const.file }
- my_consts = constants. group_by { |const| const.file }
-
- other_consts.each do |file, consts|
- next if my_consts.include? file
-
- consts.each do |const|
- add_constant const
- end
+ merge_collections constants, class_module.constants do |const|
+ add_constant const
end
- class_module.each_include do |incl|
+ merge_collections includes, class_module.includes do |incl|
add_include incl
end
@@ -351,6 +338,17 @@ def merge class_module
end
end
+ def merge_collections mine, other, &block # :nodoc:
+ my_things = mine. group_by { |thing| thing.file }
+ other_things = other.group_by { |thing| thing.file }
+
+ other_things.each do |file, things|
+ next if my_things.include? file
+
+ things.each(&block)
+ end
+ end
+
##
# Does this object represent a module?
View
7 lib/rdoc/context.rb
@@ -492,8 +492,11 @@ def add_constant constant
##
# Adds included module +include+ which should be an RDoc::Include
- def add_include(include)
- add_to @includes, include unless @includes.map { |i| i.full_name }.include?( include.full_name )
+ def add_include include
+ add_to @includes, include unless
+ @includes.map { |i| i.full_name }.include? include.full_name
+
+ include
end
##
View
47 test/test_rdoc_class_module.rb
@@ -94,6 +94,7 @@ def test_marshal_dump
c1.record_location tl
i1 = RDoc::Include.new 'I1', ''
+ i1.record_location tl
cm.add_attribute a1
cm.add_attribute a2
@@ -124,6 +125,8 @@ def test_marshal_dump
assert_equal tl, loaded.attributes.first.file
assert_equal tl, loaded.constants.first.file
+
+ assert_equal tl, loaded.includes.first.file
end
def test_marshal_load_version_0
@@ -177,7 +180,6 @@ def test_merge
cm1 = RDoc::ClassModule.new 'Klass'
cm1.add_comment 'klass 1', tl
- cm1.add_include RDoc::Include.new('I1', '')
cm1.add_method RDoc::AnyMethod.new(nil, 'm1')
cm2 = RDoc::ClassModule.new 'Klass'
@@ -186,7 +188,6 @@ def test_merge
@RM::Document.new(
@RM::Paragraph.new('klass 2')))
- cm2.add_include RDoc::Include.new('I2', '')
cm2.add_method RDoc::AnyMethod.new(nil, 'm2')
cm1.merge cm2
@@ -201,14 +202,6 @@ def test_merge
assert_equal expected, cm1.comment
expected = [
- RDoc::Include.new('I1', ''),
- RDoc::Include.new('I2', ''),
- ]
-
- expected.each do |i| i.parent = cm1 end
- assert_equal expected, cm1.includes.sort
-
- expected = [
RDoc::AnyMethod.new(nil, 'm1'),
RDoc::AnyMethod.new(nil, 'm2'),
]
@@ -288,6 +281,40 @@ def test_merge_constants
assert_equal expected, cm1.constants.sort
end
+ def test_merge_includes
+ tl1 = RDoc::TopLevel.new 'one.rb'
+ tl2 = RDoc::TopLevel.new 'two.rb'
+
+ cm1 = RDoc::ClassModule.new 'Klass'
+
+ incl = cm1.add_include RDoc::Include.new('I1', 'one')
+ incl.record_location tl1
+ incl = cm1.add_include RDoc::Include.new('I3', 'one')
+ incl.record_location tl1
+
+ cm2 = RDoc::ClassModule.new 'Klass'
+ cm2.instance_variable_set :@comment, @RM::Document.new
+
+ incl = cm2.add_include RDoc::Include.new('I2', 'two')
+ incl.record_location tl2
+ incl = cm2.add_include RDoc::Include.new('I3', 'two')
+ incl.record_location tl1
+ incl = cm2.add_include RDoc::Include.new('I4', 'two')
+ incl.record_location tl1
+
+ cm1.merge cm2
+
+ expected = [
+ RDoc::Include.new('I1', 'one'),
+ RDoc::Include.new('I2', 'two'),
+ RDoc::Include.new('I3', 'one'),
+ ]
+
+ expected.each do |a| a.parent = cm1 end
+
+ assert_equal expected, cm1.includes.sort
+ end
+
# # TODO use merge with a version 0 ClassModule
# def test_merge_version_0
# tl = RDoc::TopLevel.new 'file.rb'
View
1  test/test_rdoc_ri_driver.rb
@@ -912,6 +912,7 @@ def util_store
doc = @RM::Document.new @RM::Paragraph.new('Include thingy')
@cFooInc = RDoc::Include.new 'Inc', doc
+ @cFooInc.record_location @top_level
@cFoo.add_include @cFooInc
@cFoo_Bar = RDoc::NormalClass.new 'Bar'
View
2  test/test_rdoc_ri_store.rb
@@ -40,7 +40,9 @@ def setup
@nest_klass = @klass.add_class RDoc::NormalClass, 'SubClass'
@nest_meth = RDoc::AnyMethod.new nil, 'method'
@nest_meth.record_location @top_level
+
@nest_incl = RDoc::Include.new 'Incl', ''
+ @nest_incl.record_location @top_level
@nest_klass.add_method @nest_meth
@nest_klass.add_include @nest_incl
Please sign in to comment.
Something went wrong with that request. Please try again.