undefined method `current' for Engines:Module - fixed!

This post is a bit of a Part II to my previous undefined method `last' for {}:Hash-post. I was following Nathaniel's Gotcha post, but at some point I apparently fell off the wagon.
I got this error:
vendor/plugins/datetime_toolbocks/init.rb:25:in `evaluate_init_rb': undefined method `current' for Engines:Module (NoMethodError)
And I just could not figure out what the problem was, until today, when I went back and re-re-re-read Nathaniel's post. I spotted this paragraph:
"Engines.current.version no longer exists, so if you want that sort of functionality to see what version the engine is..."
I had read it many times before, but it just didn't make any sense to me (as a non-seasoned Ruby/Rails developer). I had no need "for that sort of functionality" in my head. But the "Engines.current.version" caught my eye, as that was the line that was giving me a kick [] in my... either way. It's now very clear. In vendor/plugins/datetime_toolbocks/lib/datetime_toolbocks.rb somewhere within the DatetimeToolbocks module, add these two lines:
mattr_accessor :version
self.version = false

Then in vendor/plugins/datetime_toolbocks/init.rb replace
Engines.current.version = Proc.new { File.open(File.join(RAILS_ROOT, 'vendor', 'plugins', 'datetime_toolbocks', 'VERSION'), 'r').readlines[0] }
DatetimeToolbocks.version = Proc.new { File.open(File.join(RAILS_ROOT, 'vendor', 'plugins', 'datetime_toolbawks', 'VERSION')
, 'r').readlines[0] }

Crystal clear!
Now you should be able to run something like:
user@box $ ./script/runner 'puts Rails::VERSION::STRING'
user@box $

without getting any errors. Tickety-boo! I hope this clarifies things for someone out there.

What puzzles me a bit is that these changes are made in the DatetimeToolbocks, which is built by Nathaniel.... wouldn't it have been smarter to update DatetimeToolbocks...? I'm sure that'll happen, and I'm sure there's a valid reason for things being the way they are (there always is). And I really don't want to come across as some ungrateful pr*ck; I do like DatetimeToolbocks and I am grateful for Nathaniel's work (and underlying Date widget). :)

No comments: