Shouldn't loading have a callback?
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
pkg
test
var
.gitignore
.index
.travis.yml
Gemfile
HISTORY.md
LICENSE.txt
MANIFEST.txt
README.md
Rakefile
Toolchain

README.md

Homepage | Report Issue | Source Code ( Build Status )

Backload

Shouldn't loading have a callback?

Installation

Using RubyGems type on a command line:

$ gem install backload

Instruction

To use Backload simply override the Kernel.backloaded method.

  require 'backload'
  require 'backload/require_relative'

  def Kernel.backloaded(feature, options={})
    if options[:require]
      if rel = options[:relative]
        puts "#{feature} has been required relative to #{rel}!"
      else
        puts "#{feature} has been required!"
      end
    else
      if wrap = options[:wrap]
        puts "#{feature} has been loaded with wrap, it's #{wrap}!"  
      else
        puts "#{feature} has been loaded!" 
      end
    end
  end

Becuase of implementation details, #require_relative has to be reimplemented completely to make the callback work. To be on the safe side, at least for now, it therefore has to be required separately, as the example above demonstrates.

Backload also provides callbacks for each type of loading. Just use the past tense of the term for any of #load, #require and #require_relative. For example, to see all features as they have been required.

  def Kernel.required(feature)
    puts "#{feature} required!"
  end

Feedback

Please report issues or suggestions to GitHub Issues. Or if you wish to discuss in real-time try IRC #rubyworks on freenode.net.

Copying

Backload is copyrighted open source software.

Copyright 2012 Rubyworks.

It is modifiable and redistributable in accordance with the BSD-2-Clause license.

See LICENSE.txt for details.