diff --git a/HISTORY.md b/HISTORY.md index b681494..c4d475a 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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`. @@ -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 @@ -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. diff --git a/MANIFEST.txt b/MANIFEST.txt index c0721b6..fd286d8 100644 --- a/MANIFEST.txt +++ b/MANIFEST.txt @@ -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 diff --git a/README.md b/README.md index 71454ba..66069b7 100644 --- a/README.md +++ b/README.md @@ -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}!" @@ -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. diff --git a/lib/backload.rb b/lib/backload.rb new file mode 100644 index 0000000..fe71992 --- /dev/null +++ b/lib/backload.rb @@ -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 + diff --git a/lib/backload/autoload.rb b/lib/backload/autoload.rb new file mode 100644 index 0000000..6ed9f5e --- /dev/null +++ b/lib/backload/autoload.rb @@ -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 diff --git a/lib/backload/load.rb b/lib/backload/load.rb new file mode 100644 index 0000000..78f3996 --- /dev/null +++ b/lib/backload/load.rb @@ -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 diff --git a/lib/loaded/require.rb b/lib/backload/require.rb similarity index 51% rename from lib/loaded/require.rb rename to lib/backload/require.rb index 4fde427..66ff69e 100644 --- a/lib/loaded/require.rb +++ b/lib/backload/require.rb @@ -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. @@ -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 @@ -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 diff --git a/lib/loaded/require_relative.rb b/lib/backload/require_relative.rb similarity index 77% rename from lib/loaded/require_relative.rb rename to lib/backload/require_relative.rb index 4973146..12fe52e 100644 --- a/lib/loaded/require_relative.rb +++ b/lib/backload/require_relative.rb @@ -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. @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/lib/loaded.rb b/lib/loaded.rb deleted file mode 100644 index 392e37c..0000000 --- a/lib/loaded.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Kernel - protected - - # - # We create a noop method for loaded b/c it simplifes - # implementation. Just override this method to use. - # - def self.loaded(path, options={}) - end -end - -require 'loaded/load' -require 'loaded/require' - -# for not this is an optional feature ? -#require 'loaded/require_relative' - diff --git a/lib/loaded/load.rb b/lib/loaded/load.rb deleted file mode 100644 index d2ff68a..0000000 --- a/lib/loaded/load.rb +++ /dev/null @@ -1,52 +0,0 @@ -module Kernel - private - - # - # Alias original Kernel#load method. - # - alias_method :load_without_callback, :load - - # - # Redefine Kernel#load with callback. - # - def load(feature, options=nil) - if not Hash === options - wrap = options - options = {:wrap => wrap} - end - options[:load] = true - options[:require] = false - - result = load_without_callback(feature, options[:wrap]) - - Kernel.loaded(feature, options) if result - - result - end - - class << self - # - # Alias original Kernel.load method. - # - alias_method :load_without_callback, :load - - # - # Redefine Kernel.load with callback. - # - def load(feature, options=nil) - if not Hash === options - wrap = options - options = {:wrap => wrap} - end - options[:load] = true - options[:require] = false - - result = load_without_callback(feature, options[:wrap]) - - Kernel.loaded(feature, options) if result - - result - end - end - -end diff --git a/var/description b/var/description index dc1f2af..6c3bac0 100644 --- a/var/description +++ b/var/description @@ -1 +1 @@ -Loaded provides callbacks for Ruby's #require and #load methods. +Backload provides callbacks for Ruby's #require and #load methods. diff --git a/var/name b/var/name index 28aa623..cd1aa49 100644 --- a/var/name +++ b/var/name @@ -1 +1 @@ -loaded +backload diff --git a/var/organization b/var/organization index 5568880..a2119fd 100644 --- a/var/organization +++ b/var/organization @@ -1 +1,2 @@ -rubyworks +--- +- Rubyworks diff --git a/var/repositories b/var/repositories index 8f438d0..c0daa44 100644 --- a/var/repositories +++ b/var/repositories @@ -1,2 +1,2 @@ --- -upstream: git://github.com/rubyworks/loaded.git +upstream: git://github.com/rubyworks/backload.git diff --git a/var/resources b/var/resources index 4281df5..ed91aea 100644 --- a/var/resources +++ b/var/resources @@ -1,5 +1,5 @@ --- -home: http://rubyworks.github.com/loaded -code: http://github.com/rubyworks/loaded -bugs: http://github.com/rubyworks/loaded/issues +home: http://rubyworks.github.com/backload +code: http://github.com/rubyworks/backload +bugs: http://github.com/rubyworks/backload/issues diff --git a/var/summary b/var/summary index f120e19..c930770 100644 --- a/var/summary +++ b/var/summary @@ -1 +1 @@ -Callbacks for #load and #require +Callbacks for #require and #load. diff --git a/var/title b/var/title index 50b5b54..31ac74c 100644 --- a/var/title +++ b/var/title @@ -1 +1 @@ -Loaded +Backload diff --git a/var/version b/var/version index 17e51c3..0ea3a94 100644 --- a/var/version +++ b/var/version @@ -1 +1 @@ -0.1.1 +0.2.0