Skip to content

rubyworks/backload

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Sep 27, 2018
fd4b3fc · Sep 27, 2018

History

44 Commits
Dec 23, 2012
Jan 14, 2014
Dec 23, 2012
Jan 14, 2014
Jan 14, 2014
Jan 14, 2014
Jan 14, 2014
Jan 14, 2014
Dec 23, 2012
Apr 29, 2012
Jan 14, 2014
Sep 27, 2018
Dec 23, 2012
Jan 14, 2014

Repository files navigation

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

Because 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.

About

Shouldn't loading have a callback?

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages