https://github.com/rubyworks/backload
Shouldn't loading have a callback?
https://github.com/rubyworks/backload
Last synced: 6 months ago
JSON representation
Shouldn't loading have a callback?
- Host: GitHub
- URL: https://github.com/rubyworks/backload
- Owner: rubyworks
- License: other
- Created: 2012-04-29T16:06:30.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2018-09-27T12:22:47.000Z (over 7 years ago)
- Last Synced: 2024-12-01T17:52:43.719Z (about 1 year ago)
- Language: Ruby
- Size: 848 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[Homepage](http://rubygems.org/gems/backload) |
[Report Issue](http://github.com/rubyworks/backload/issues) |
[Source Code](http://github.com/rubyworks/backload)
( [](http://travis-ci.org/rubyworks/backload) )
# 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.
```ruby
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.
```ruby
def Kernel.required(feature)
puts "#{feature} required!"
end
```
## Feedback
Please report issues or suggestions to
[GitHub Issues](http://github.com/rubyworks/backload/issues).
Or if you wish to discuss in real-time try [IRC #rubyworks](irc://chat.us.freenet.org/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.