Finally, I found the problem :-D
The problem
In your Rails project, you have at least one file that contains a whitespace (in my personal case, I had a copy of a file and the filename was quality_metric copy.rb
).
The solution
Remove either the file or the whitespace, run yardoc
to force the regeneration of the checksums-file and everything should be fine.
Explanation
The problem appears when Yard tries to load the checksums for the files (the following code snippet is from the file yard/registry_store.rb
):
def load_checksums
return unless File.file?(checksums_path)
lines = File.readlines(checksums_path).map do |line|
line.strip.split(/\s+/)
end
@checksums = Hash[lines]
end
Yard stores the checksums and the according filenames in a file called .yardoc/checksums
. When it reads the file in, it reads all lines individually, splits the line by whitespace and stores it into an array (in the codesnippet, that's the lines
-variable). In the case of a file containing a whitespace in the name (in particular case, quality_metric copy.rb
), then this gets parsed into something like
["app/models/quality_metric", "copy.rb", "5034a5e72b3814040aa4bc6881890ab42d72d941"]
The Hash::[]
-method then takes an array of arrays, but assumes that all the subarrays are either of length 1 or 2. When it gets an array of length 3, for instance, it returns the following error message:
ArgumentError: invalid number of elements (3 for 1..2)
So, the error actually has nothing to do with Yard itself, which is why it was so nifty to hunt it down.