My plugin folder is now organized based on the SU guidelines for extensions.
I have noticed that some authors extend the search path for Ruby with something like
basedir = File.dirname(__FILE__) $:.push(File.join(basedir, 'plugin_folder_name'))
This allows to
require files without specifying the path.
I was wondering whether this is actually a good idea. If two authors create a file with the same name, then only the first file would be loaded from
require and this is not necessarily the right one. Am I understanding it correctly?
I was thinking to a way to make the plugin independent from the main plugin file in the
Plugin folder and I thought that the following approach should work. I first define three constants:
PLUGIN_NAME = File.basename( __FILE__, ".*").freeze PLUGIN_PATH_ROOT = File.dirname( __FILE__ ).freeze PLUGIN_PATH = File.join( PLUGIN_PATH_ROOT, PLUGIN_NAME ).freeze
I would then replace all the requires in my code with
require File.join(PLUGIN_PATH, 'file_required')
In this way, if I want to change the plugin name (and I need to do that in the future) I can simply change the main
rb file and the corresponding folder name
Is this the recommended approach?
Corollary question about
require: would it make sense to put all the requires in the
loader file within the respective plugin folder?