Skip to content

Commit

Permalink
Rename project to backload. [major]
Browse files Browse the repository at this point in the history
  • Loading branch information
trans committed Dec 23, 2012
1 parent b273d33 commit f933ae8
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 115 deletions.
21 changes: 18 additions & 3 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# RELEASE HISTORY

## 0.1.1 | 2012-12-19
## 0.2.0 / 2012-12-22

Change the name of the project from Loaded to Backload, and
changed the main callback method from `#loaded` to `#backloaded`.
Then re-added `#loaded`, `#required` and `#required_relative` as
straight callbacks for their corresponding present-tense methods.
This makes the library backward compatible with v0.1.0.

Changes:

* Rename project to "backload".
* Add basic callbacks for load, require and require_relative.
* Master callback is renamed to `#backloaded`.


## 0.1.1 / 2012-12-19

Just a tweak to require_relative support, so that the `:relative`
option provides the relative path, not just `true` or `false`.
Expand All @@ -10,7 +25,7 @@ Changes:
* The :relative option provides the relative path.


## 0.1.0 | 2012-12-18
## 0.1.0 / 2012-12-18

This release uses a single callback method `#loaded` instead
of the previous two (`#loaded` and `#required`). It also adds
Expand All @@ -22,7 +37,7 @@ Changes:
* Add support for #require_relative.


## 0.0.1 | 2012-04-29
## 0.0.1 / 2012-04-29

Initial release of Loaded.

Expand Down
9 changes: 5 additions & 4 deletions MANIFEST.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!mast -x *.lock .yardopts .index .ruby bin demo lib man spec test try [A-Z]*.*
.index
lib/loaded/load.rb
lib/loaded/require.rb
lib/loaded/require_relative.rb
lib/loaded.rb
lib/backload/autoload.rb
lib/backload/load.rb
lib/backload/require.rb
lib/backload/require_relative.rb
lib/backload.rb
test/fixtures/example_load.rb
test/fixtures/example_relative.rb
test/fixtures/example_require.rb
Expand Down
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
[Homepage](http://rubygems.org/gems/loaded) |
[Report Issue](http://github.com/rubyworks/loaded/issues) |
[Source Code](http://github.com/rubyworks/loaded)
( [![Build Status](https://secure.travis-ci.org/rubyworks/loaded.png)](http://travis-ci.org/rubyworks/loaded) )
[Homepage](http://rubygems.org/gems/backload) |
[Report Issue](http://github.com/rubyworks/backload/issues) |
[Source Code](http://github.com/rubyworks/backload)
( [![Build Status](https://secure.travis-ci.org/rubyworks/backload.png)](http://travis-ci.org/rubyworks/backload) )


# Loaded
# Backload

Shouldn't loading have a callback?

Note the change in API from v. 0.0 to 0.1. Now there is only one callback method, namely `#loaded`,
that both `#load` and `#require` call. Which was used can be determined by the `options` argument.


## Installation

Using RubyGems type on a command line:

$ gem install loaded
$ gem install backload


## Instruction

To use the loaded callback simply override `Kernel.loaded` method.
To use Backload simply override the `Kernel.backloaded` method.

```ruby
require 'loaded'
require 'loaded/require_relative'
require 'backload'
require 'backload/require_relative'

def Kernel.loaded(feature, options={})
def Kernel.backloaded(feature, options={})
if options[:require]
if rel = options[:relative]
puts "#{feature} has been required relative to #{rel}!"
Expand All @@ -48,11 +45,20 @@ Becuase of implementation details, `#require_relative` has to be reimplemented c
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/required/issues).
[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.


Expand Down
29 changes: 29 additions & 0 deletions lib/backload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'backload/load'
require 'backload/require'
#require 'backload/require_relative'

module Kernel

# Common callback for all loading methods: #load, #require
# and #require_relative.
#
# @param [Hash] options
# The load callback options.
#
# @option options [Boolean] :load
# True if #load was used.
#
# @option options [Boolean] :require
# True is #require or #require_relative was used.
#
# @option options [Boolean] :relative
# True is #require_relative was used.
#
# @option options [Boolean] :wrap
# The wrap argument passed to #load.
#
def self.backloaded(path, options={})
end

end

12 changes: 12 additions & 0 deletions lib/backload/autoload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This does not look doable in pure Ruby.

#module Kernel
#
# #
# # We create a noop method b/c it simplifes implementation.
# # Just override this method to use.
# #
# def self.autoloaded(path, options={})
# end
#
#end
52 changes: 52 additions & 0 deletions lib/backload/load.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module Kernel

#
# We create a noop method b/c it simplifes implementation.
# Just override this method to use.
#
def self.loaded(path, wrap=nil)
end

private

#
# Alias original Kernel#load method.
#
alias_method :load_without_callback, :load

#
# Redefine Kernel#load with callback.
#
def load(path, wrap=nil)
result = load_without_callback(feature, options[:wrap])

if result
Kernel.loaded(path, wrap)
Kernel.backloaded(path, :load=>true, :require=>false, :wrap=>wrap)
end

result
end

class << self
#
# Alias original Kernel.load method.
#
alias_method :load_without_callback, :load

#
# Redefine Kernel.load with callback.
#
def load(path, wrap=nil)
result = load_without_callback(path, wrap)

if result
Kernel.loaded(path, wrap)
Kernel.backloaded(path, :load=>true, :require=>false, :wrap=>wrap)
end

result
end
end

end
26 changes: 19 additions & 7 deletions lib/loaded/require.rb → lib/backload/require.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
module Kernel
private

#
# We create a noop method b/c it simplifes implementation.
# Just override this method to use.
#
def self.required(path)
end

private

#
# Alias original Kernel#require method.
Expand All @@ -10,10 +18,12 @@ module Kernel
# Redefine Kernel#require with callback.
#
def require(feature, options=nil)
options = {:require => true, :load => false}
result = require_without_callback(feature)

Kernel.loaded(feature, options) if result
if result
Kernel.required(feature)
Kernel.backloaded(feature, :require=>true, :load=>false)
end

result
end
Expand All @@ -27,11 +37,13 @@ class << self
#
# Redefine Kernel.require with callback.
#
def require(feature, options=nil)
options = {:require => true, :load => false}
result = require_without_callback(feature)
def require(feature)
result = require_without_callback(feature)

Kernel.loaded(feature, options) if result
if result
Kernel.required(feature)
Kernel.backloaded(feature, :require=>true, :load=>false)
end

result
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
module Kernel
private

#
# We create a noop method b/c it simplifes implementation.
# Just override this method to use.
#
# Presently this is an optional feature and must be required
# separately via `backload/require_relative`.
#
def self.required_relative(path)
end

private

#
# Alias original Kernel#require_relative method.
Expand All @@ -13,8 +24,6 @@ module Kernel
# realtive path, but that would require `Binding.of_caller`.
#
def require_relative(feature, options=nil)
options = {:require => true, :relative => true, :load => false}

#result = require_relative_without_callback(feature)

## We have to reimplement #require_relative instead of calling
Expand All @@ -28,10 +37,13 @@ def require_relative(feature, options=nil)
end
options[:relative] = File.dirname(file)
absolute = File.expand_path(feature, File.dirname(file))
require_without_callback absolute
require_without_callback(absolute)
)

Kernel.loaded(feature, options) if result
if result
Kernel.required_relative(feature)
Kernel.backloaded(feature, :require=>true, :load=>false, :relative=>true)
end

result
end
Expand All @@ -49,8 +61,6 @@ class << self
# realtive path, but that would require `Binding.of_caller`.
#
def require_relative(feature, options=nil)
options = {:require => true, :relative => true, :load => false}

#result = require_relative_without_callback(feature)

## We have to reimplement #require_relative instead of calling
Expand All @@ -67,7 +77,10 @@ def require_relative(feature, options=nil)
require_without_callback absolute
)

Kernel.loaded(feature, options) if result
if result
Kernel.required_relative(feature)
Kernel.backloaded(feature, :require=>true, :load=>false, :relative=>true)
end

result
end
Expand Down
17 changes: 0 additions & 17 deletions lib/loaded.rb

This file was deleted.

Loading

0 comments on commit f933ae8

Please sign in to comment.