Project

backload

0.0
No commit activity in last 3 years
No release in over 3 years
Backload provides callbacks for Ruby's #require and #load methods.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

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.