yard 0.5.0 → 0.5.1p1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of yard might be problematic. Click here for more details.
- data/ChangeLog +51 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/docs/WhatsNew.md +47 -19
- data/lib/yard.rb +2 -2
- data/lib/yard/cli/yardoc.rb +24 -21
- data/lib/yard/cli/yri.rb +18 -3
- data/lib/yard/core_ext/file.rb +9 -0
- data/lib/yard/parser/ruby/ruby_parser.rb +1 -0
- data/lib/yard/parser/source_parser.rb +4 -3
- data/lib/yard/registry.rb +18 -2
- data/lib/yard/registry_store.rb +46 -23
- data/lib/yard/serializers/file_system_serializer.rb +1 -4
- data/spec/cli/yri_spec.rb +25 -1
- data/spec/core_ext/file_spec.rb +16 -0
- data/spec/parser/ruby/ruby_parser_spec.rb +0 -4
- data/spec/parser/source_parser_spec.rb +0 -1
- data/spec/registry_spec.rb +69 -0
- data/spec/registry_store_spec.rb +1 -1
- data/spec/yard_spec.rb +8 -0
- metadata +4 -4
data/ChangeLog
CHANGED
@@ -1,3 +1,54 @@
|
|
1
|
+
2009-12-16 Loren Segal <lsegal@soen.ca>
|
2
|
+
|
3
|
+
* ChangeLog, lib/yard.rb: Bump version to 0.5.1p1
|
4
|
+
|
5
|
+
* lib/yard/cli/yri.rb, lib/yard/core_ext/file.rb, lib/yard/registry_store.rb,
|
6
|
+
lib/yard/serializers/file_system_serializer.rb, spec/core_ext/file_spec.rb:
|
7
|
+
Ensure '~/.yard' path is created before writing certain config files. - Adds
|
8
|
+
File.open! to ensure path exists before writing file Closes gh-57
|
9
|
+
|
10
|
+
* lib/yard/registry_store.rb: Return true/false in RegistryStore#load!
|
11
|
+
|
12
|
+
2009-12-15 Loren Segal <lsegal@soen.ca>
|
13
|
+
|
14
|
+
* docs/WhatsNew.md: Forgot to add version number for changes
|
15
|
+
|
16
|
+
* ChangeLog, README.md, lib/yard.rb, yard.gemspec: Bump version to 0.5.1
|
17
|
+
|
18
|
+
* docs/WhatsNew.md: Update What's New document
|
19
|
+
|
20
|
+
* lib/yard/cli/yri.rb, spec/cli/yri_spec.rb: Always put local directory's
|
21
|
+
.yardoc ahead of cache
|
22
|
+
|
23
|
+
* lib/yard/cli/yri.rb, spec/cli/yri_spec.rb: Allow user to specify
|
24
|
+
~/.yard/yri_search_paths file listing extra yardoc dbs to search. File
|
25
|
+
format should just be newline separated .yardoc files/directories:
|
26
|
+
/path/to/.yardoc /path/to/other.yardoc ...
|
27
|
+
|
28
|
+
* lib/yard/cli/yardoc.rb: Improve behaviour of re-generating changed objects
|
29
|
+
during incremental parsing
|
30
|
+
|
31
|
+
* lib/yard/registry.rb, lib/yard/registry_store.rb,
|
32
|
+
spec/registry_store_spec.rb: Change behaviour of RegistryStore loading cache.
|
33
|
+
Does not load cache on #keys/#values by default. Instead use #load! or
|
34
|
+
#load_all to load all contents explicitly
|
35
|
+
|
36
|
+
* lib/yard/parser/source_parser.rb, spec/parser/source_parser_spec.rb: Change
|
37
|
+
behaviour of SourceParser logging
|
38
|
+
|
39
|
+
* lib/yard/registry_store.rb: Add cache for failed lookups
|
40
|
+
|
41
|
+
* lib/yard/parser/ruby/ruby_parser.rb, spec/parser/ruby/ruby_parser_spec.rb:
|
42
|
+
Fix RubyParser in 1.9.1p376 (ripper lib was changed)
|
43
|
+
|
44
|
+
* lib/yard/registry.rb, spec/registry_spec.rb: Add specs for
|
45
|
+
Registry.yardoc_file_for_gem
|
46
|
+
|
47
|
+
* lib/yard.rb, lib/yard/cli/yri.rb, lib/yard/registry.rb, spec/yard_spec.rb:
|
48
|
+
Add support for packages named yard-doc-* to be loaded by yri
|
49
|
+
|
50
|
+
* Rakefile: Should use RUBY_PLATFORM
|
51
|
+
|
1
52
|
2009-12-14 Loren Segal <lsegal@soen.ca>
|
2
53
|
|
3
54
|
* ChangeLog, README.md, docs/WhatsNew.md, lib/yard.rb, yard.gemspec: Bump
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/lib/yard'
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'rake/gempackagetask'
|
4
4
|
|
5
|
-
WINDOWS = (
|
5
|
+
WINDOWS = (RUBY_PLATFORM =~ /win32|cygwin/ ? true : false) rescue false
|
6
6
|
SUDO = WINDOWS ? '' : 'sudo'
|
7
7
|
|
8
8
|
task :default => :specs
|
data/docs/WhatsNew.md
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
What's New in 0.5.x?
|
2
2
|
====================
|
3
3
|
|
4
|
-
1. **Support for documenting native Ruby C code**
|
5
|
-
2. **Incremental parsing and output generation with `yardoc -c`**
|
6
|
-
2. **Improved `yri` support to perform lookups on installed Gems**
|
7
|
-
3. **Added `yardoc --default-return` and `yardoc --hide-void-return`**
|
8
|
-
4. **Multiple syntax highlighting language support**
|
9
|
-
5. **New .yardoc format**
|
10
|
-
|
11
|
-
Support for
|
12
|
-
|
4
|
+
1. **Support for documenting native Ruby C code** (0.5.0)
|
5
|
+
2. **Incremental parsing and output generation with `yardoc -c`** (0.5.0)
|
6
|
+
2. **Improved `yri` support to perform lookups on installed Gems** (0.5.0)
|
7
|
+
3. **Added `yardoc --default-return` and `yardoc --hide-void-return`** (0.5.0)
|
8
|
+
4. **Multiple syntax highlighting language support** (0.5.0)
|
9
|
+
5. **New .yardoc format** (0.5.0)
|
10
|
+
6. **Support for yard-doc-* gem packages as hosted .yardoc dbs** (0.5.1)
|
11
|
+
7. **Support for extra search paths in `yri`** (0.5.1)
|
12
|
+
|
13
|
+
Support for documenting native Ruby C code (0.5.0)
|
14
|
+
--------------------------------------------------
|
13
15
|
|
14
16
|
It is now possible to document native Ruby extensions with YARD with a new
|
15
17
|
C parser mostly borrowed from RDoc. This enables the ability to document
|
@@ -17,8 +19,8 @@ Ruby's core and stdlibs which will be hosted on http://yardoc.org/docs. In
|
|
17
19
|
addition, the .yardoc dump for the Ruby-core classes will become available
|
18
20
|
as an installable gem for yri support (see #3).
|
19
21
|
|
20
|
-
Incremental parsing and output generation with `yardoc -c`
|
21
|
-
|
22
|
+
Incremental parsing and output generation with `yardoc -c` (0.5.0)
|
23
|
+
------------------------------------------------------------------
|
22
24
|
|
23
25
|
YARD now compares file checksums before parsing when using `yardoc -c`
|
24
26
|
(aka `yardoc --use-cache`) to do incremental parsing of only the files that
|
@@ -29,8 +31,8 @@ remember that when using incremental output generation, the index will not
|
|
29
31
|
be rebuilt and inter-file links might not hook up right, so it is best to
|
30
32
|
perform a full rebuild at the end of such previews.
|
31
33
|
|
32
|
-
Improved `yri` support to perform lookups on installed Gems
|
33
|
-
|
34
|
+
Improved `yri` support to perform lookups on installed Gems (0.5.0)
|
35
|
+
-------------------------------------------------------------------
|
34
36
|
|
35
37
|
The `yri` executable can now perform lookups on gems that have been parsed
|
36
38
|
by yard. Therefore, to use this command you must first parse all gems with
|
@@ -51,8 +53,8 @@ You can now do lookups with yri:
|
|
51
53
|
All lookups are cached to `~/.yard/yri_cache` for quicker lookups the second
|
52
54
|
time onward.
|
53
55
|
|
54
|
-
Added `yardoc --default-return` and `yardoc --hide-void-return`
|
55
|
-
|
56
|
+
Added `yardoc --default-return` and `yardoc --hide-void-return` (0.5.0)
|
57
|
+
-----------------------------------------------------------------------
|
56
58
|
|
57
59
|
YARD defaults to displaying (Object) as the default return type of any
|
58
60
|
method that has not declared a @return tag. To customize the default
|
@@ -65,8 +67,8 @@ You can also use the empty string to list no return type.
|
|
65
67
|
In addition, you can use --hide-void-return to ignore any method that
|
66
68
|
defines itself as a void type by: `@return [void]`
|
67
69
|
|
68
|
-
Multiple syntax highlighting language support
|
69
|
-
|
70
|
+
Multiple syntax highlighting language support (0.5.0)
|
71
|
+
-----------------------------------------------------
|
70
72
|
|
71
73
|
YARD now supports the ability to specify a language type for code blocks in
|
72
74
|
docstrings. Although no actual highlighting support is added for any language
|
@@ -87,8 +89,8 @@ To use this language in code blocks, prefix the block with `!!!LANGNAME`:
|
|
87
89
|
By the same token. you can now use `!!!plain` to ignore highlighting for
|
88
90
|
a specific code block.
|
89
91
|
|
90
|
-
New .yardoc format
|
91
|
-
|
92
|
+
New .yardoc format (0.5.0)
|
93
|
+
--------------------------
|
92
94
|
|
93
95
|
To make the above yri support possible, the .yardoc format was redesigned
|
94
96
|
to be a directory instead of a file. YARD can still load old .yardoc files,
|
@@ -96,6 +98,32 @@ but they will be automatically upgraded if re-saved. The new .yardoc format
|
|
96
98
|
does have a larger memory footprint, but this will hopefully be optimized
|
97
99
|
downward.
|
98
100
|
|
101
|
+
Support for yard-doc-* gem packages as hosted .yardoc dbs (0.5.1)
|
102
|
+
-----------------------------------------------------------------
|
103
|
+
|
104
|
+
You can now install special YARD plugin gems titled yard-doc-NAME to get
|
105
|
+
packaged a .yardoc database. This will enable yri lookups or building docs
|
106
|
+
for the gem without the code.
|
107
|
+
|
108
|
+
One main use for this is the `yard-doc-core` package, which enabled yri
|
109
|
+
support for Ruby core classes (stdlib coming soon as `yard-doc-stdlib`).
|
110
|
+
To install it, simply:
|
111
|
+
|
112
|
+
$ sudo gem install yard-doc-core
|
113
|
+
# now you can use:
|
114
|
+
$ yri String
|
115
|
+
|
116
|
+
This will by default install the 1.9.1 core library. To install a library
|
117
|
+
for a specific version of Ruby, use the `--version` switch on gem:
|
118
|
+
|
119
|
+
$ sudo gem install --version '= 1.8.6' yard-doc-core
|
120
|
+
|
121
|
+
Support for extra search paths in `yri` (0.5.1)
|
122
|
+
-----------------------------------------------
|
123
|
+
|
124
|
+
You can now add custom paths to non-gem .yardoc files
|
125
|
+
by adding them as newline separated paths in `~/.yard/yri_search_paths`.
|
126
|
+
|
99
127
|
|
100
128
|
What's New in 0.4.x?
|
101
129
|
====================
|
data/lib/yard.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module YARD
|
2
|
-
VERSION = "0.5.
|
2
|
+
VERSION = "0.5.1p1"
|
3
3
|
ROOT = File.dirname(__FILE__)
|
4
4
|
TEMPLATE_ROOT = File.join(File.dirname(__FILE__), '..', 'templates')
|
5
5
|
CONFIG_DIR = File.expand_path('~/.yard')
|
@@ -33,7 +33,7 @@ module YARD
|
|
33
33
|
|
34
34
|
Gem.source_index.find_name('').each do |gem|
|
35
35
|
begin
|
36
|
-
if gem.name =~ /^yard[-_]/ && !ignored_plugins.include?(gem.name)
|
36
|
+
if gem.name =~ /^yard[-_](?!doc-)/ && !ignored_plugins.include?(gem.name)
|
37
37
|
log.debug "Loading plugin '#{gem.name}'..."
|
38
38
|
require gem.name
|
39
39
|
end
|
data/lib/yard/cli/yardoc.rb
CHANGED
@@ -61,18 +61,16 @@ module YARD
|
|
61
61
|
optparse(*yardopts)
|
62
62
|
optparse(*args)
|
63
63
|
|
64
|
-
|
64
|
+
if use_cache
|
65
|
+
Registry.load
|
66
|
+
checksums = Registry.checksums.dup
|
67
|
+
end
|
65
68
|
YARD.parse(files)
|
66
69
|
Registry.save(use_cache)
|
67
70
|
|
68
71
|
if generate
|
69
72
|
if use_cache
|
70
|
-
|
71
|
-
Registry.all # load all
|
72
|
-
objects.each do |object|
|
73
|
-
opts = options.merge(:object => object, :type => :layout)
|
74
|
-
Templates::Engine.render(opts)
|
75
|
-
end
|
73
|
+
generate_with_cache(checksums)
|
76
74
|
else
|
77
75
|
Templates::Engine.generate(all_objects, options)
|
78
76
|
end
|
@@ -80,25 +78,13 @@ module YARD
|
|
80
78
|
|
81
79
|
true
|
82
80
|
end
|
83
|
-
|
81
|
+
|
84
82
|
# The list of all objects to process. Override this method to change
|
85
83
|
# which objects YARD should generate documentation for.
|
86
84
|
#
|
87
85
|
# @return [Array<CodeObjects::Base>] a list of code objects to process
|
88
86
|
def all_objects
|
89
|
-
|
90
|
-
if use_cache
|
91
|
-
Registry.paths(false).map do |path|
|
92
|
-
obj = Registry.at(path)
|
93
|
-
if types.include?(obj.type)
|
94
|
-
obj
|
95
|
-
else
|
96
|
-
nil
|
97
|
-
end
|
98
|
-
end.compact
|
99
|
-
else
|
100
|
-
Registry.all(*types)
|
101
|
-
end
|
87
|
+
Registry.all(:root, :module, :class)
|
102
88
|
end
|
103
89
|
|
104
90
|
# Parses the .yardopts file for default yard options
|
@@ -111,6 +97,23 @@ module YARD
|
|
111
97
|
|
112
98
|
private
|
113
99
|
|
100
|
+
# Generates output for changed objects in cache
|
101
|
+
# @return [void]
|
102
|
+
def generate_with_cache(checksums)
|
103
|
+
changed_files = []
|
104
|
+
Registry.checksums.each do |file, hash|
|
105
|
+
changed_files << file if checksums[file] != hash
|
106
|
+
end
|
107
|
+
Registry.load_all
|
108
|
+
all_objects.each do |object|
|
109
|
+
if object.files.any? {|f, line| changed_files.include?(f) }
|
110
|
+
log.info "Re-generating object #{object.path}..."
|
111
|
+
opts = options.merge(:object => object, :type => :layout)
|
112
|
+
Templates::Engine.render(opts)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
114
117
|
# Reads a .document file in the directory to get source file globs
|
115
118
|
# @return [void]
|
116
119
|
def support_rdoc_document_file!
|
data/lib/yard/cli/yri.rb
CHANGED
@@ -3,6 +3,7 @@ module YARD
|
|
3
3
|
# A tool to view documentation in the console like `ri`
|
4
4
|
class YRI < Base
|
5
5
|
CACHE_FILE = File.expand_path('~/.yard/yri_cache')
|
6
|
+
SEARCH_PATHS_FILE = File.expand_path('~/.yard/yri_search_paths')
|
6
7
|
|
7
8
|
# Helper method to run the utility on an instance.
|
8
9
|
# @see #run
|
@@ -10,7 +11,8 @@ module YARD
|
|
10
11
|
|
11
12
|
def initialize
|
12
13
|
@cache = {}
|
13
|
-
@search_paths = [
|
14
|
+
@search_paths = []
|
15
|
+
add_default_paths
|
14
16
|
add_gem_paths
|
15
17
|
load_cache
|
16
18
|
@search_paths.uniq!
|
@@ -40,7 +42,7 @@ module YARD
|
|
40
42
|
return if path == Registry.yardoc_file
|
41
43
|
@cache[name] = path
|
42
44
|
|
43
|
-
File.open(CACHE_FILE, 'w') do |file|
|
45
|
+
File.open!(CACHE_FILE, 'w') do |file|
|
44
46
|
@cache.each do |key, value|
|
45
47
|
file.puts("#{key} #{value}")
|
46
48
|
end
|
@@ -58,9 +60,11 @@ module YARD
|
|
58
60
|
|
59
61
|
def find_object(name)
|
60
62
|
@search_paths.unshift(@cache[name]) if @cache[name]
|
63
|
+
@search_paths.unshift(Registry.yardoc_file)
|
61
64
|
|
62
65
|
log.debug "Searching for #{name} in search paths"
|
63
66
|
@search_paths.each do |path|
|
67
|
+
next unless File.exist?(path)
|
64
68
|
log.debug "Searching for #{name} in #{path}..."
|
65
69
|
Registry.load(path)
|
66
70
|
obj = Registry.at(name)
|
@@ -86,12 +90,23 @@ module YARD
|
|
86
90
|
require 'rubygems'
|
87
91
|
Gem.source_index.find_name('').each do |spec|
|
88
92
|
if yfile = Registry.yardoc_file_for_gem(spec.name)
|
89
|
-
|
93
|
+
if spec.name =~ /^yard-doc-/
|
94
|
+
@search_paths.unshift(yfile)
|
95
|
+
else
|
96
|
+
@search_paths.push(yfile)
|
97
|
+
end
|
90
98
|
end
|
91
99
|
end
|
92
100
|
rescue LoadError
|
93
101
|
end
|
94
102
|
|
103
|
+
# Adds paths in {SEARCH_PATHS_FILE}
|
104
|
+
def add_default_paths
|
105
|
+
return unless File.file?(SEARCH_PATHS_FILE)
|
106
|
+
paths = File.readlines(SEARCH_PATHS_FILE).map {|l| l.strip }
|
107
|
+
@search_paths.push(*paths)
|
108
|
+
end
|
109
|
+
|
95
110
|
# Parses commandline options.
|
96
111
|
# @param [Array<String>] args each tokenized argument
|
97
112
|
def optparse(*args)
|
data/lib/yard/core_ext/file.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
1
3
|
class File
|
2
4
|
RELATIVE_PARENTDIR = '..'
|
3
5
|
RELATIVE_SAMEDIR = '.'
|
@@ -40,4 +42,11 @@ class File
|
|
40
42
|
end
|
41
43
|
File.join(*path)
|
42
44
|
end
|
45
|
+
|
46
|
+
# Forces opening a file (for writing) by first creating the file's directory
|
47
|
+
def self.open!(file, *args, &block)
|
48
|
+
dir = dirname(file)
|
49
|
+
FileUtils.mkdir_p(dir) unless directory?(dir)
|
50
|
+
open(file, *args, &block)
|
51
|
+
end
|
43
52
|
end
|
@@ -145,9 +145,10 @@ module YARD
|
|
145
145
|
@file = content
|
146
146
|
content = IO.read(content)
|
147
147
|
checksum = Registry.checksum_for(content)
|
148
|
-
if Registry.checksums[file] == checksum
|
149
|
-
|
150
|
-
|
148
|
+
return if Registry.checksums[file] == checksum
|
149
|
+
|
150
|
+
if Registry.checksums.has_key?(file)
|
151
|
+
log.info "File '#{file}' was modified, re-processing..."
|
151
152
|
end
|
152
153
|
Registry.checksums[@file] = checksum
|
153
154
|
self.parser_type = parser_type_for_filename(file)
|
data/lib/yard/registry.rb
CHANGED
@@ -48,7 +48,14 @@ module YARD
|
|
48
48
|
# @return [nil] if +for_writing+ is set to false and no yardoc file
|
49
49
|
# is found, returns nil.
|
50
50
|
def yardoc_file_for_gem(gem, ver_require = ">= 0", for_writing = false)
|
51
|
-
spec = Gem.source_index.find_name(gem, ver_require)
|
51
|
+
spec = Gem.source_index.find_name(gem, ver_require)
|
52
|
+
return if spec.empty?
|
53
|
+
spec = spec.first
|
54
|
+
|
55
|
+
if gem =~ /^yard-doc-/
|
56
|
+
path = File.join(spec.full_gem_path, DEFAULT_YARDOC_FILE)
|
57
|
+
return File.exist?(path) && !for_writing ? path : nil
|
58
|
+
end
|
52
59
|
|
53
60
|
if for_writing
|
54
61
|
global_yardoc_file(spec, for_writing) ||
|
@@ -136,6 +143,15 @@ module YARD
|
|
136
143
|
@store.load(file)
|
137
144
|
end
|
138
145
|
|
146
|
+
def load!(file = yardoc_file)
|
147
|
+
clear
|
148
|
+
@store.load!(file)
|
149
|
+
end
|
150
|
+
|
151
|
+
def load_all
|
152
|
+
@store.load_all
|
153
|
+
end
|
154
|
+
|
139
155
|
# Saves the registry to +file+
|
140
156
|
#
|
141
157
|
# @param [String] file the yardoc file to save to
|
@@ -184,7 +200,7 @@ module YARD
|
|
184
200
|
# Returns the paths of all of the objects in the registry.
|
185
201
|
# @param [Boolean] reload whether to load entire database
|
186
202
|
# @return [Array<String>] all of the paths in the registry.
|
187
|
-
def paths(reload =
|
203
|
+
def paths(reload = false)
|
188
204
|
@store.keys(reload).map {|k| k.to_s }
|
189
205
|
end
|
190
206
|
|
data/lib/yard/registry_store.rb
CHANGED
@@ -13,6 +13,7 @@ module YARD
|
|
13
13
|
@checksums = {}
|
14
14
|
@store = { :root => CodeObjects::RootObject.new(nil, :root) }
|
15
15
|
@proxy_types = {}
|
16
|
+
@notfound = {}
|
16
17
|
@loaded_objects = 0
|
17
18
|
@available_objects = 0
|
18
19
|
end
|
@@ -26,12 +27,16 @@ module YARD
|
|
26
27
|
key = :root if key == ''
|
27
28
|
key = key.to_sym
|
28
29
|
return @store[key] if @store[key]
|
29
|
-
return
|
30
|
+
return if @loaded_objects >= @available_objects
|
30
31
|
|
31
32
|
# check disk
|
33
|
+
return if @notfound[key]
|
32
34
|
if obj = @serializer.deserialize(key)
|
33
35
|
@loaded_objects += 1
|
34
36
|
put(key, obj)
|
37
|
+
else
|
38
|
+
@notfound[key] = true
|
39
|
+
nil
|
35
40
|
end
|
36
41
|
end
|
37
42
|
|
@@ -58,7 +63,7 @@ module YARD
|
|
58
63
|
# @param [Boolean] reload if false, does not load the entire database
|
59
64
|
# before a lookup.
|
60
65
|
# @return [Array<Symbol>] the path names of all the code objects
|
61
|
-
def keys(reload =
|
66
|
+
def keys(reload = false) load_all if reload; @store.keys end
|
62
67
|
|
63
68
|
# Gets all code objects from the store. Loads the entire database
|
64
69
|
# if +reload+ is +true+
|
@@ -66,7 +71,7 @@ module YARD
|
|
66
71
|
# @param [Boolean] reload if false, does not load the entire database
|
67
72
|
# before a lookup.
|
68
73
|
# @return [Array<CodeObjects::Base>] all the code objects
|
69
|
-
def values(reload =
|
74
|
+
def values(reload = false) load_all if reload; @store.values end
|
70
75
|
|
71
76
|
# @return [CodeObjects::RootObject] the root object
|
72
77
|
def root; @store[:root] end
|
@@ -77,9 +82,45 @@ module YARD
|
|
77
82
|
@file = file
|
78
83
|
@store = {}
|
79
84
|
@proxy_types = {}
|
85
|
+
@notfound = {}
|
80
86
|
@serializer = Serializers::YardocSerializer.new(@file)
|
81
87
|
load_yardoc
|
82
88
|
end
|
89
|
+
|
90
|
+
# Loads the .yardoc file and loads all cached objects into memory
|
91
|
+
# automatically.
|
92
|
+
#
|
93
|
+
# @param [String, nil] file the name of the yardoc db to load
|
94
|
+
# @return [Boolean] whether the database was loaded
|
95
|
+
# @see #load_all
|
96
|
+
def load!(file = nil)
|
97
|
+
if load(file)
|
98
|
+
load_all
|
99
|
+
true
|
100
|
+
else
|
101
|
+
false
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Loads all cached objects into memory
|
106
|
+
# @return [void]
|
107
|
+
def load_all
|
108
|
+
return unless @file
|
109
|
+
return if @loaded_objects >= @available_objects
|
110
|
+
log.debug "Loading entire database: #{@file} ..."
|
111
|
+
objects = []
|
112
|
+
|
113
|
+
all_disk_objects.sort_by {|x| x.size }.each do |path|
|
114
|
+
if obj = @serializer.deserialize(path, true)
|
115
|
+
objects << obj
|
116
|
+
end
|
117
|
+
end
|
118
|
+
objects.each do |obj|
|
119
|
+
put(obj.path, obj)
|
120
|
+
end
|
121
|
+
@loaded_objects += objects.size
|
122
|
+
log.debug "Loaded database (file='#{@file}' count=#{objects.size} total=#{@available_objects})"
|
123
|
+
end
|
83
124
|
|
84
125
|
# Saves the database to disk
|
85
126
|
# @param [Boolean] merge if true, merges the data in memory with the
|
@@ -177,35 +218,17 @@ module YARD
|
|
177
218
|
@store[:root] = root
|
178
219
|
end
|
179
220
|
end
|
180
|
-
|
181
|
-
def load_all
|
182
|
-
return unless @file
|
183
|
-
return if @loaded_objects >= @available_objects
|
184
|
-
log.debug "Loading entire database: #{@file} ..."
|
185
|
-
objects = []
|
186
|
-
|
187
|
-
all_disk_objects.sort_by {|x| x.size }.each do |path|
|
188
|
-
if obj = @serializer.deserialize(path, true)
|
189
|
-
objects << obj
|
190
|
-
end
|
191
|
-
end
|
192
|
-
objects.each do |obj|
|
193
|
-
put(obj.path, obj)
|
194
|
-
end
|
195
|
-
@loaded_objects += objects.size
|
196
|
-
log.debug "Loaded database (file='#{@file}' count=#{objects.size} total=#{@available_objects})"
|
197
|
-
end
|
198
221
|
|
199
222
|
def all_disk_objects
|
200
223
|
Dir.glob(File.join(objects_path, '**/*')).select {|f| File.file?(f) }
|
201
224
|
end
|
202
225
|
|
203
226
|
def write_proxy_types
|
204
|
-
File.open(proxy_types_path, 'wb') {|f| f.write(Marshal.dump(@proxy_types)) }
|
227
|
+
File.open!(proxy_types_path, 'wb') {|f| f.write(Marshal.dump(@proxy_types)) }
|
205
228
|
end
|
206
229
|
|
207
230
|
def write_checksums
|
208
|
-
File.open(checksums_path, 'w') do |f|
|
231
|
+
File.open!(checksums_path, 'w') do |f|
|
209
232
|
@checksums.each {|k, v| f.puts("#{k} #{v}") }
|
210
233
|
end
|
211
234
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
1
|
module YARD
|
4
2
|
module Serializers
|
5
3
|
class FileSystemSerializer < Base
|
@@ -28,9 +26,8 @@ module YARD
|
|
28
26
|
# @return [String] the written data (for chaining)
|
29
27
|
def serialize(object, data)
|
30
28
|
path = File.join(basepath, *serialized_path(object))
|
31
|
-
FileUtils.mkdir_p File.dirname(path)
|
32
29
|
log.debug "Serializing to #{path}"
|
33
|
-
File.open(path, "wb") {|f| f.write data }
|
30
|
+
File.open!(path, "wb") {|f| f.write data }
|
34
31
|
end
|
35
32
|
|
36
33
|
# Implements the serialized path of a code object.
|
data/spec/cli/yri_spec.rb
CHANGED
@@ -13,11 +13,22 @@ describe YARD::CLI::Yardoc do
|
|
13
13
|
describe '#find_object' do
|
14
14
|
it "should use cache if available" do
|
15
15
|
@yri.stub!(:cache_object)
|
16
|
+
File.should_receive(:exist?).with('.yardoc').and_return(false)
|
17
|
+
File.should_receive(:exist?).with('bar.yardoc').and_return(true)
|
16
18
|
Registry.should_receive(:load).with('bar.yardoc')
|
17
19
|
Registry.should_receive(:at).with('Foo').and_return('OBJ')
|
18
20
|
@yri.instance_variable_set("@cache", {'Foo' => 'bar.yardoc'})
|
19
21
|
@yri.find_object('Foo').should == 'OBJ'
|
20
|
-
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should never use cache ahead of current directory's .yardoc" do
|
25
|
+
@yri.stub!(:cache_object)
|
26
|
+
File.should_receive(:exist?).with('.yardoc').and_return(true)
|
27
|
+
Registry.should_receive(:load).with('.yardoc')
|
28
|
+
Registry.should_receive(:at).with('Foo').and_return('OBJ')
|
29
|
+
@yri.instance_variable_set("@cache", {'Foo' => 'bar.yardoc'})
|
30
|
+
@yri.find_object('Foo').should == 'OBJ'
|
31
|
+
@yri.instance_variable_get("@search_paths")[0].should == '.yardoc'
|
21
32
|
end
|
22
33
|
end
|
23
34
|
|
@@ -27,4 +38,17 @@ describe YARD::CLI::Yardoc do
|
|
27
38
|
@yri.cache_object('Foo', Registry.yardoc_file)
|
28
39
|
end
|
29
40
|
end
|
41
|
+
|
42
|
+
describe '#initialize' do
|
43
|
+
it "should load search paths" do
|
44
|
+
path = %r{/\.yard/yri_search_paths$}
|
45
|
+
File.should_receive(:file?).with(%r{/\.yard/yri_cache$}).and_return(false)
|
46
|
+
File.should_receive(:file?).with(path).and_return(true)
|
47
|
+
File.should_receive(:readlines).with(path).and_return(%w(line1 line2))
|
48
|
+
@yri = YARD::CLI::YRI.new
|
49
|
+
spaths = @yri.instance_variable_get("@search_paths")
|
50
|
+
spaths.should include('line1')
|
51
|
+
spaths.should include('line2')
|
52
|
+
end
|
53
|
+
end
|
30
54
|
end
|
data/spec/core_ext/file_spec.rb
CHANGED
@@ -45,4 +45,20 @@ describe File do
|
|
45
45
|
File.cleanpath('C/../../D').should == "../D"
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
describe '.open!' do
|
50
|
+
it "should create the path before opening" do
|
51
|
+
File.should_receive(:directory?).with('/path/to').and_return(false)
|
52
|
+
FileUtils.should_receive(:mkdir_p).with('/path/to')
|
53
|
+
File.should_receive(:open).with('/path/to/file', 'w')
|
54
|
+
File.open!('/path/to/file', 'w')
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should just open the file if the path exists" do
|
58
|
+
File.should_receive(:directory?).with('/path/to').and_return(true)
|
59
|
+
FileUtils.should_not_receive(:mkdir_p)
|
60
|
+
File.should_receive(:open).with('/path/to/file', 'w')
|
61
|
+
File.open!('/path/to/file', 'w')
|
62
|
+
end
|
63
|
+
end
|
48
64
|
end
|
@@ -109,7 +109,6 @@ describe YARD::Parser::SourceParser do
|
|
109
109
|
hash = Registry.checksum_for(data)
|
110
110
|
cmock = mock(:cmock)
|
111
111
|
cmock.should_receive(:[]).with('foo/bar').and_return(hash)
|
112
|
-
log.should_receive(:info)
|
113
112
|
Registry.should_receive(:checksums).and_return(cmock)
|
114
113
|
File.should_receive(:file?).with('foo/bar').and_return(true)
|
115
114
|
IO.should_receive(:read).with('foo/bar').and_return(data)
|
data/spec/registry_spec.rb
CHANGED
@@ -4,6 +4,75 @@ include CodeObjects
|
|
4
4
|
describe YARD::Registry do
|
5
5
|
before { Registry.clear }
|
6
6
|
|
7
|
+
describe '.yardoc_file_for_gem' do
|
8
|
+
before do
|
9
|
+
@gem = mock('gem')
|
10
|
+
@gem.stub!(:name).and_return('foo')
|
11
|
+
@gem.stub!(:full_name).and_return('foo-1.0')
|
12
|
+
@gem.stub!(:full_gem_path).and_return('/path/to/foo')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return nil if gem isn't found" do
|
16
|
+
Gem.source_index.should_receive(:find_name).with('foo', '>= 0').and_return([])
|
17
|
+
Registry.yardoc_file_for_gem('foo').should == nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should allow version to be specified" do
|
21
|
+
Gem.source_index.should_receive(:find_name).with('foo', '= 2').and_return([])
|
22
|
+
Registry.yardoc_file_for_gem('foo', '= 2').should == nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return existing .yardoc path for gem when for_writing=false" do
|
26
|
+
File.should_receive(:exist?).and_return(false)
|
27
|
+
File.should_receive(:exist?).with('/path/to/foo/.yardoc').and_return(true)
|
28
|
+
Gem.source_index.should_receive(:find_name).with('foo', '>= 0').and_return([@gem])
|
29
|
+
Registry.yardoc_file_for_gem('foo').should == '/path/to/foo/.yardoc'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return nil if no .yardoc path exists in gem when for_writing=false" do
|
33
|
+
File.should_receive(:exist?).and_return(false)
|
34
|
+
File.should_receive(:exist?).with('/path/to/foo/.yardoc').and_return(false)
|
35
|
+
Gem.source_index.should_receive(:find_name).with('foo', '>= 0').and_return([@gem])
|
36
|
+
Registry.yardoc_file_for_gem('foo').should == nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should search local gem path first if for_writing=false" do
|
40
|
+
File.should_receive(:exist?).and_return(true)
|
41
|
+
Gem.source_index.should_receive(:find_name).with('foo', '>= 0').and_return([@gem])
|
42
|
+
Registry.yardoc_file_for_gem('foo').should =~ %r{/.yard/gem_index/foo-1.0.yardoc$}
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return global .yardoc path for gem if for_writing=true and dir is writable" do
|
46
|
+
File.should_receive(:writable?).with(@gem.full_gem_path).and_return(true)
|
47
|
+
Gem.source_index.should_receive(:find_name).with('foo', '>= 0').and_return([@gem])
|
48
|
+
Registry.yardoc_file_for_gem('foo', '>= 0', true).should == '/path/to/foo/.yardoc'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return local .yardoc path for gem if for_writing=true and dir is not writable" do
|
52
|
+
File.should_receive(:writable?).with(@gem.full_gem_path).and_return(false)
|
53
|
+
Gem.source_index.should_receive(:find_name).with('foo', '>= 0').and_return([@gem])
|
54
|
+
Registry.yardoc_file_for_gem('foo', '>= 0', true).should =~ %r{/.yard/gem_index/foo-1.0.yardoc$}
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return gem path if gem starts with yard-doc- and for_writing=false" do
|
58
|
+
@gem.stub!(:name).and_return('yard-doc-core')
|
59
|
+
@gem.stub!(:full_name).and_return('yard-doc-core-1.0')
|
60
|
+
@gem.stub!(:full_gem_path).and_return('/path/to/yard-doc-core')
|
61
|
+
Gem.source_index.should_receive(:find_name).with('yard-doc-core', '>= 0').and_return([@gem])
|
62
|
+
File.should_receive(:exist?).with('/path/to/yard-doc-core/.yardoc').and_return(true)
|
63
|
+
Registry.yardoc_file_for_gem('yard-doc-core').should == '/path/to/yard-doc-core/.yardoc'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return nil if gem starts with yard-doc- and for_writing=true" do
|
67
|
+
@gem.stub!(:name).and_return('yard-doc-core')
|
68
|
+
@gem.stub!(:full_name).and_return('yard-doc-core-1.0')
|
69
|
+
@gem.stub!(:full_gem_path).and_return('/path/to/yard-doc-core')
|
70
|
+
Gem.source_index.should_receive(:find_name).with('yard-doc-core', '>= 0').and_return([@gem])
|
71
|
+
File.should_receive(:exist?).with('/path/to/yard-doc-core/.yardoc').and_return(true)
|
72
|
+
Registry.yardoc_file_for_gem('yard-doc-core', '>= 0', true).should == nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
7
76
|
describe '#root' do
|
8
77
|
it "should have an empty path for root" do
|
9
78
|
Registry.root.path.should == ""
|
data/spec/registry_store_spec.rb
CHANGED
@@ -115,7 +115,7 @@ describe YARD::RegistryStore do
|
|
115
115
|
File.should_receive(:directory?).with('foo').and_return(true)
|
116
116
|
@store.load('foo')
|
117
117
|
@store.should_receive(:load_all)
|
118
|
-
@store.send(item)
|
118
|
+
@store.send(item, true)
|
119
119
|
end
|
120
120
|
|
121
121
|
it "should not load entire database if reload=false" do
|
data/spec/yard_spec.rb
CHANGED
@@ -43,5 +43,13 @@ describe YARD do
|
|
43
43
|
log.should_receive(:debug).with(/Loading plugin 'yard-plugin3'/).once
|
44
44
|
YARD.load_plugins.should == true
|
45
45
|
end
|
46
|
+
|
47
|
+
it "should not load plugins starting with yard-doc-" do
|
48
|
+
mock = mock('yard-doc-core')
|
49
|
+
mock.should_receive(:name).at_least(1).times.and_return('yard-doc-core')
|
50
|
+
Gem.source_index.should_receive(:find_name).with('').and_return([mock])
|
51
|
+
YARD.should_not_receive(:require)
|
52
|
+
YARD.load_plugins.should == true
|
53
|
+
end
|
46
54
|
end
|
47
55
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1p1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loren Segal
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-16 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -371,9 +371,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
371
371
|
version:
|
372
372
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
373
373
|
requirements:
|
374
|
-
- - "
|
374
|
+
- - ">"
|
375
375
|
- !ruby/object:Gem::Version
|
376
|
-
version:
|
376
|
+
version: 1.3.1
|
377
377
|
version:
|
378
378
|
requirements: []
|
379
379
|
|