Reputation: 6377
I am trying to document my Rails application with yard. yardoc
produces the desired output in the doc folder. Then I fire up yard server
, and I get the message
>> YARD 0.8.7.6 documentation server at http://0.0.0.0:8808
[2014-12-05 17:09:51] INFO WEBrick 1.3.1
[2014-12-05 17:09:51] INFO ruby 2.1.2 (2014-05-08) [x86_64-darwin13.0]
[2014-12-05 17:09:51] INFO WEBrick::HTTPServer#start: pid=70736 port=8808
So far everything as expected.
But as soon as I try to navigate to the given url, I end up with the following error message:
invalid number of elements (3 for 1..2)
Unfortunately, I have no idea what's going on here. I tried to search for the error message, but didn't find a solution. Any help would be appreciated.
Upvotes: 1
Views: 837
Reputation: 6377
Finally, I found the problem :-D
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
).
Remove either the file or the whitespace, run yardoc
to force the regeneration of the checksums-file and everything should be fine.
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.
Upvotes: 1