Permalink
Browse files

- Add an optional type parameter to Gem::Specification#doc_dir.

Use Gem::Specification#doc_dir in Gem::RDoc and reduce exposed attributes inside Gem::RDoc.
  • Loading branch information...
1 parent bfafdb4 commit a45d5f8e488cc096b4ea121d7c20c0a8582c475d @drbrain drbrain committed Jun 7, 2011
Showing with 45 additions and 32 deletions.
  1. +4 −1 .autotest
  2. +4 −12 lib/rubygems/rdoc.rb
  3. +13 −2 lib/rubygems/specification.rb
  4. +16 −17 test/rubygems/test_gem_rdoc.rb
  5. +8 −0 test/rubygems/test_gem_specification.rb
View
@@ -35,6 +35,9 @@ end
class Autotest
alias :old_path_to_classname :path_to_classname
def path_to_classname s
- old_path_to_classname(s.sub(/test.rubygems.test_/, ""))
+ classname = old_path_to_classname(s.sub(/test.rubygems.test_/, ""))
+ classname = classname.gsub('Rdoc', 'RDoc')
+
+ classname
end
end
View
@@ -32,11 +32,6 @@ class Gem::RDoc
@specs = []
##
- # Documentation dir for this specification
-
- attr_reader :doc_dir
-
- ##
# Force installation of documentation?
attr_accessor :force
@@ -51,9 +46,6 @@ class Gem::RDoc
attr_accessor :generate_ri
- attr_reader :rdoc_dir
- attr_reader :ri_dir
-
##
# Specification to be documented
@@ -116,11 +108,11 @@ def initialize spec, generate_rdoc = true, generate_ri = true
@rdoc = nil
@spec = spec
- @generate_ri = generate_ri
@generate_rdoc = generate_rdoc
+ @generate_ri = generate_ri
- @ri_dir = File.join @doc_dir, 'ri' # TODO Gem::Specification#doc_dir 'ri'
- @rdoc_dir = File.join @doc_dir, 'rdoc'
+ @rdoc_dir = spec.doc_dir 'rdoc'
+ @ri_dir = spec.doc_dir 'ri'
end
##
@@ -281,7 +273,7 @@ def remove
raise Gem::FilePermissionError, base_dir unless File.writable? base_dir
- FileUtils.rm_rf @doc_dir
+ FileUtils.rm_rf @rdoc_dir
FileUtils.rm_rf @ri_dir
end
@@ -1346,10 +1346,21 @@ def development_dependencies
end
##
- # Returns the full path to this spec's documentation directory.
+ # Returns the full path to this spec's documentation directory. If +type+
+ # is given it will be appended to the end. For examlpe:
+ #
+ # spec.doc_dir # => "/path/to/gem_repo/doc/a-1"
+ #
+ # spec.doc_dir 'ri' # => "/path/to/gem_repo/doc/a-1/ri"
- def doc_dir
+ def doc_dir type = nil
@doc_dir ||= File.join base_dir, 'doc', full_name
+
+ if type then
+ File.join @doc_dir, type
+ else
+ @doc_dir
+ end
end
def encode_with coder # :nodoc:
@@ -26,9 +26,6 @@ def test_initialize
assert @rdoc.generate_rdoc
assert @rdoc.generate_ri
- assert_equal "#{@a.doc_dir}/rdoc", @rdoc.rdoc_dir
- assert_equal "#{@a.doc_dir}/ri", @rdoc.ri_dir
-
rdoc = Gem::RDoc.new @a, false, false
refute rdoc.generate_rdoc
@@ -57,7 +54,7 @@ def test_document
@rdoc.instance_variable_set :@rdoc, @rdoc.new_rdoc
@rdoc.instance_variable_set :@file_info, []
- @rdoc.document 'darkfish', options, @rdoc.rdoc_dir
+ @rdoc.document 'darkfish', options, @a.doc_dir('rdoc')
assert @rdoc.rdoc_installed?
end
@@ -87,29 +84,29 @@ def test_generate_disabled
def test_generate_force
skip 'RDoc 3+ required' unless rdoc_3?
- FileUtils.mkdir_p @rdoc.rdoc_dir
- FileUtils.mkdir_p @rdoc.ri_dir
+ FileUtils.mkdir_p @a.doc_dir 'ri'
+ FileUtils.mkdir_p @a.doc_dir 'rdoc'
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
@rdoc.force = true
@rdoc.generate
- assert_path_exists File.join(@rdoc.rdoc_dir, 'index.html')
- assert_path_exists File.join(@rdoc.ri_dir, 'cache.ri')
+ assert_path_exists File.join(@a.doc_dir('rdoc'), 'index.html')
+ assert_path_exists File.join(@a.doc_dir('ri'), 'cache.ri')
end
def test_generate_no_overwrite
skip 'RDoc 3+ required' unless rdoc_3?
- FileUtils.mkdir_p @rdoc.rdoc_dir
- FileUtils.mkdir_p @rdoc.ri_dir
+ FileUtils.mkdir_p @a.doc_dir 'ri'
+ FileUtils.mkdir_p @a.doc_dir 'rdoc'
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
@rdoc.generate
- refute_path_exists File.join(@rdoc.rdoc_dir, 'index.html')
- refute_path_exists File.join(@rdoc.ri_dir, 'created.rid')
+ refute_path_exists File.join(@a.doc_dir('rdoc'), 'index.html')
+ refute_path_exists File.join(@a.doc_dir('ri'), 'cache.ri')
end
def test_generate_legacy
@@ -126,7 +123,7 @@ def test_legacy_rdoc
FileUtils.mkdir_p @a.doc_dir
FileUtils.mkdir_p File.join(@a.gem_dir, 'lib')
- @rdoc.legacy_rdoc '--op', @rdoc.rdoc_dir
+ @rdoc.legacy_rdoc '--op', @a.doc_dir('rdoc')
assert @rdoc.rdoc_installed?
end
@@ -138,19 +135,21 @@ def test_new_rdoc
def test_rdoc_installed?
refute @rdoc.rdoc_installed?
- FileUtils.mkdir_p @rdoc.rdoc_dir
+ FileUtils.mkdir_p @a.doc_dir 'rdoc'
assert @rdoc.rdoc_installed?
end
def test_remove
- FileUtils.mkdir_p @rdoc.rdoc_dir
- FileUtils.mkdir_p @rdoc.ri_dir
+ FileUtils.mkdir_p @a.doc_dir 'rdoc'
+ FileUtils.mkdir_p @a.doc_dir 'ri'
@rdoc.remove
refute @rdoc.rdoc_installed?
refute @rdoc.ri_installed?
+
+ assert_path_exists @a.doc_dir
end
def test_remove_unwritable
@@ -170,7 +169,7 @@ def test_remove_unwritable
def test_ri_installed?
refute @rdoc.ri_installed?
- FileUtils.mkdir_p @rdoc.ri_dir
+ FileUtils.mkdir_p @a.doc_dir 'ri'
assert @rdoc.ri_installed?
end
@@ -405,6 +405,14 @@ def test_dependencies
assert_equal [@bonobo, @monkey], @gem.dependencies
end
+ def test_doc_dir
+ assert_equal File.join(@gemhome, 'doc', 'a-1'), @a1.doc_dir
+ end
+
+ def test_doc_dir_type
+ assert_equal File.join(@gemhome, 'doc', 'a-1', 'ri'), @a1.doc_dir('ri')
+ end
+
def test_runtime_dependencies
util_setup_deps
assert_equal [@bonobo], @gem.runtime_dependencies

0 comments on commit a45d5f8

Please sign in to comment.