Permalink
Browse files

Creating a TopLevel no longer changes global state

RDoc::TopLevel.new used to use global state to wire the newly created
file into the documentation tree.  Now you must use RDoc::Store#add_file
to add files to the documentation tree.  This is a step towards allowing
multiple parsers to run in the same process.
  • Loading branch information...
1 parent 31a477c commit fcc8eba5ad8c70a95a5b82b69bb252f163e38ec7 @drbrain drbrain committed Aug 9, 2012
View
@@ -7,19 +7,21 @@
RDoc::RI::Store will be removed in RDoc 5.
Tests that create RDoc::CodeObjects on the fly without wiring them into
- the documentation tree (did not use add_class, add_method, etc.) will need
- to be updated to use these methods. The documentation tree automatically
+ the documentation tree (did not use add_class, add_method, etc.) must be
+ updated to use these methods. The documentation tree automatically
attaches them to the store instance which allows lookups to work
- correctly.
+ correctly. Additionally, a new method RDoc::Store#add_file must be used
+ instead of RDoc::TopLevel.new. The latter will not be attached to the
+ documentation tree.
+ * RDoc generators must accept an RDoc::Store and an RDoc::Options in
+ initialize. RDoc no longer passes an Array of RDoc::TopLevel objects to
+ #generate. Use RDoc::Store#all_files instead.
* The default output encoding for RDoc is now UTF-8. Previously RDoc used
the default external encoding which was determined from your locale.
Issue #106 by Justin Baker.
* Removed RDoc::RI::Paths::SYSDIR and ::SITEDIR. These were hidden
constants so no breakage is expected. Use RDoc::RI::Paths::system_dir
and ::site_dir instead.
- * RDoc generators must accept an RDoc::Store and an RDoc::Options in
- initialize. RDoc no longer passes an Array of RDoc::TopLevel objects to
- #generate. Use RDoc::Store#all_files instead.
* Minor enhancements
* Added Markdown as a supported format. The markdown format can be set on a
View
@@ -220,6 +220,15 @@ def param_seq
end
##
+ # Sets the store for this method and its referenced code objects.
+
+ def store= store
+ super
+
+ @file = @store.add_file @file.full_name if @file
+ end
+
+ ##
# For methods that +super+, find the superclass method that would be called.
def superclass_method
View
@@ -71,6 +71,15 @@ def path
"#{@parent.path}##{@name}"
end
+ ##
+ # Sets the store for this class or module and its contained code objects.
+
+ def store= store
+ super
+
+ @file = @store.add_file @file.full_name if @file
+ end
+
def to_s # :nodoc:
parent_name = parent ? parent.full_name : '(unknown)'
if is_alias_for
View
@@ -531,7 +531,7 @@ def add_to array, thing
array << thing if @document_self
thing.parent = self
- thing.store = @store
+ thing.store = @store if @store
thing.section = current_section
end
View
@@ -100,6 +100,15 @@ def module
@name
end
+ ##
+ # Sets the store for this class or module and its contained code objects.
+
+ def store= store
+ super
+
+ @file = @store.add_file @file.full_name if @file
+ end
+
def to_s # :nodoc:
"extend #@name in: #{parent}"
end
View
@@ -102,6 +102,15 @@ def module
@name
end
+ ##
+ # Sets the store for this class or module and its contained code objects.
+
+ def store= store
+ super
+
+ @file = @store.add_file @file.full_name if @file
+ end
+
def to_s # :nodoc:
"include #@name in: #{parent}"
end
View
@@ -133,6 +133,15 @@ def see
@see
end
+ ##
+ # Sets the store for this class or module and its contained code objects.
+
+ def store= store
+ super
+
+ @file = @store.add_file @file.full_name if @file
+ end
+
def find_see # :nodoc:
return nil if singleton || is_alias_for
View
@@ -342,7 +342,7 @@ def parse_file filename
return unless content
- top_level = RDoc::TopLevel.new filename
+ top_level = @store.add_file filename
parser = RDoc::Parser.for top_level, filename, content, @options, @stats
View
@@ -75,6 +75,20 @@ def initialize path = nil, type = nil
end
##
+ # Adds the file with +name+ as an RDoc::TopLevel to the store. Returns the
+ # created RDoc::TopLevel.
+
+ def add_file name
+ unless top_level = @files_hash[name] then
+ top_level = RDoc::TopLevel.new name
+ top_level.store = self
+ @files_hash[name] = top_level
+ end
+
+ top_level
+ end
+
+ ##
# Returns all classes discovered by RDoc
def all_classes
View
@@ -33,19 +33,6 @@ class RDoc::TopLevel < RDoc::Context
attr_accessor :parser
##
- # Creates a new RDoc::TopLevel with +file_name+ only if one with the same
- # name does not exist in all_files.
-
- def self.new file_name
- store = RDoc::RDoc.current.store
- if top_level = store.files_hash[file_name] then
- top_level
- else
- super
- end
- end
-
- ##
# Creates a new TopLevel for +file_name+
def initialize file_name
@@ -58,9 +45,6 @@ def initialize file_name
@parser = nil
@classes_or_modules = []
-
- @store = RDoc::RDoc.current.store
- @store.files_hash[file_name] = self
end
##
@@ -60,7 +60,7 @@ def test_markup_code_empty
end
def test_marshal_dump
- top_level = RDoc::TopLevel.new 'file.rb'
+ top_level = @store.add_file 'file.rb'
m = RDoc::AnyMethod.new nil, 'method'
m.block_params = 'some_block'
m.call_seq = 'call_seq'
@@ -244,6 +244,14 @@ def test_parent_name
assert_equal 'C1', @c1.method_list.last.parent_name
end
+ def test_store_equals
+ loaded = Marshal.load Marshal.dump(@c1.method_list.last)
+
+ loaded.store = @store
+
+ assert_equal @store, loaded.file.store
+ end
+
def test_superclass_method
m3 = RDoc::AnyMethod.new '', 'no_super'
View
@@ -43,7 +43,7 @@ def test_full_name
end
def test_marshal_dump
- tl = RDoc::TopLevel.new 'file.rb'
+ tl = @store.add_file 'file.rb'
@a.comment = 'this is a comment'
@a.record_location tl
@@ -68,7 +68,7 @@ def test_marshal_dump
end
def test_marshal_dump_singleton
- tl = RDoc::TopLevel.new 'file.rb'
+ tl = @store.add_file 'file.rb'
@a.comment = 'this is a comment'
@a.record_location tl
Oops, something went wrong.

0 comments on commit fcc8eba

Please sign in to comment.