Project

subload

0.0
No commit activity in last 3 years
No release in over 3 years
A handy dandy autoload / require / load helper for your rubies. Similar to using[1], but with a few differences of opinion, and a bit shorter. Basically, expand path is fine, up until a point. Sometimes there's no point (i.e. when the load path already contains most of the path you're trying to open). When you're writing libs that users might require sub parts with 'libname/sub_part', then expand_path combined with say, rubygems, can lead to double requires. Lets not do that. :-) [1] http://github.com/smtlaissezfaire/using/
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 2.3.3
>= 1.0.0
>= 1.3.0
 Project Readme

subload¶ ↑

DESCRIPTION:¶ ↑

A handy dandy autoload / require / load helper for your rubies. Similar to using, but with a few differences of opinion, and a bit shorter.

Basically, expand path is fine, up until a point. Sometimes there’s no point (i.e. when the load path already contains most of the path you’re trying to open). When you’re writing libs that users might require sub parts with ‘libname/sub_part’, then expand_path combined with say, rubygems, can lead to double requires. Lets not do that. :-)

1

github.com/smtlaissezfaire/using/

FEATURES/PROBLEMS:¶ ↑

  • File.expand_path: Expand path is good if you’re traversing up directories. It is bad if you’re loading something within a library that is on the load path. If the library is on the load path, and you require files with an expanded path, there is the likelihood of a double require when other code contains a require that is expectant of the load path modification.

  • Frameworks: Sometimes require explicit load order control. In these cases, overriding the loader and either tracking, or performing stateful operations works well.

  • Abusive use of override_mode: Override mode is potentially dangerous. As per the other documentation, override mode should be reserved for use in application code only. Libraries setting override mode could cause additional failure cases for foreign libraries, although gratuitous addition of loading mechanisms is not recommended.

  • Generated code loading: When you’re doing code generation, sometimes it is desirable to have tow locations from which to load a class. One will contain custom class defintions, and the other will contain generated definitions. Using a custom loader, one can then utilise a single subload statement to correctly load both files.

  • TODO Chaotic Overloading

  • Consider vertical vs. horizontal delegation rules and use cases for new loaders in non-framework libraries that perform custom loads such that it is easy to say “invoke the current load mode with the following options”.

SYNOPSIS:¶ ↑

module A

  # The nominal use case, A.autoload :B, 'a/b'
  # You rarely need much else!
  subload :B

  # A custom path, A.autoload :C, 'a/c'
  subload :C, :path => 'a/c'
  # For example when 'a/c' defines several constants:
  subload :Ca, :path => 'a/c'
  subload :Cb, :path => 'a/c'

  # An expanded path, A.autoload :D, File.join(Dir.pwd, 'a/d')
  subload :D, :expand_path => true
  # This has interesting uses in combination, although not generally
  # recommended:
  subload :E, :path => '../../path/e', :expand_path => true

  # Explicitly override the mode, for this call only, A.require 'a/f'
  subload :F, :mode => :require

  # Set the mode for all subsiquent calls to subload in this class/module
  subload_with :require
  subload :G # => require 'a/g'
  subload :H # => require 'a/h'

  # Other features intended for library and framework developers are described
  # in the class documentation.

end

REQUIREMENTS:¶ ↑

  • ruby

INSTALL:¶ ↑

  • gem install subload

LICENSE:¶ ↑

(The MIT License)

Copyright © 2010 James Tucker <raggi@rubyforge.org>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.