]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blobdiff - bin/whatever-dl
I take that last commit back. Now the relative include path issue is fixed. The previ...
[dead/whatever-dl.git] / bin / whatever-dl
index a59e61b2d56a0c92ef5187315f1192456aa4e6fe..99183f6f2ac26e8513339001d21718f5decf9b0c 100755 (executable)
 # http://www.fsf.org/licensing/licenses/gpl.html
 #
 
+# We need Pathname to get the real filesystem path
+# of this script (and not, for example, the path of
+# a symlink which points to it.
+require 'pathname'
+
+# This bit of magic adds the parent directory (the
+# project root) to the list of ruby load paths.
+# Thus, our require statements will work regardless of
+# how or from where the script was run.
+executable = Pathname.new(__FILE__).realpath.to_s
+$: << File.dirname(executable) + '/../'
+
 # We require the UriUtilities class to handle
 # the download of the video URL.
 require 'src/uri_utilities'
 
 
+# The Dir.glob that's coming up doesn't use the
+# Ruby library path so we need to tell it where to
+# look explicitly.
+websites_pattern = File.dirname(executable) + '/../src/websites/*.rb'
+
 # All of the website classes are located in one
 # directory, so we can 'require' them automatically.
-Dir.glob('src/websites/*.rb').each do |r|
+Dir.glob(websites_pattern).each do |r|
   require r
 end