Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

like 'using', but different

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 CHANGELOG.rdoc
Octocat-spinner-32 Manifest.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 subload.gemspec
README.rdoc

subload

DESCRIPTION:

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

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.

Something went wrong with that request. Please try again.