Use Autoload
Closed this issue · 5 comments
In the main file1, you require
all the parts right at the top. I haven't documented the new plugins yet of course so this is no fault of yours but I'm going to tell everyone to use Ruby's autoload for all parts of the plugin other than the plugin class itself. The reason is simple: I am guaranteeing backwards compatibility for the Vagrant.plugin
superclass, but not anything else, so requiring the command, for example, which inherits from Vagrant::Command::Base
, will certainly crash in the future.
If you use autoload, then Vagrant can correctly NOT load those pieces in future versions.
See the Vagrant built-ins for examples: https://github.com/mitchellh/vagrant/blob/master/plugins/commands/halt/plugin.rb
Really? Autoload is deprecated and flagged for removal, so why would you want to recommend it at all? Wouldn't some kind of loading protocol (tm) be a better fit?
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/41149
Hm, I thought the autoload deprecation was reverted. Either way, after thinking on it, I think it would be easier to implement some sort of block that runs when a plugin is activated. This would be more intuitive I think for people newer to Ruby than telling them to learn about an advanced feature such as autoload. Example:
class MyPlugin < Vagrant.plugin("1")
name "my plugin"
description "A plugin!"
activated do
require "things"
require "more/things"
end
command("foo") { Things }
end
Would this be better? I think so...
Committed to Vagrant: hashicorp/vagrant@de78a36
Use the activated
block, and let me know how it goes! I'll work on converting the built-in plugins to this as well.