module Kernel

require ‘backload/require_relative’

Public Class Methods

backloaded(path, options={}) click to toggle source

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.
# File lib/backload.rb, line 25
def self.backloaded(path, options={})
end
loaded(path, wrap=nil) click to toggle source

We create a noop method b/c it simplifes implementation. Just override this method to use.

# File lib/backload/load.rb, line 7
def self.loaded(path, wrap=nil)
end
required(path) click to toggle source

We create a noop method b/c it simplifes implementation. Just override this method to use.

# File lib/backload/require.rb, line 7
def self.required(path)
end
required_relative(path) click to toggle source

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

# File lib/backload/require_relative.rb, line 10
def self.required_relative(path)
end

Private Class Methods

load(path, wrap=nil) click to toggle source

Redefine Kernel.load with callback.

# File lib/backload/load.rb, line 40
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
Also aliased as: load_without_callback
load_without_callback(path, wrap=nil)

Alias original Kernel.load method.

Alias for: load
require(feature) click to toggle source

Redefine Kernel.require with callback.

# File lib/backload/require.rb, line 40
def require(feature)
  result = require_without_callback(feature)

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

  result
end
Also aliased as: require_without_callback
require_relative(feature) click to toggle source

Redefine Kernel.require_relative with callback.

@todo It would nice if the ‘:relative` option were set to the

realtive path, but that would require `Binding.of_caller`.
# File lib/backload/require_relative.rb, line 63
def require_relative(feature)
  #result = require_relative_without_callback(feature)

  ## We have to reimplement #require_relative instead of calling
  ## the alias to ensure the proper path is used. (*sad*)
  result = (
    c = caller.first
    fail "Can't parse #{c}" unless c.rindex(/:\d+(:in `.*')?$/)
    file = $` # File.dirname(c)
    if /\A\((.*)\)/ =~ file # eval, etc.
      raise LoadError, "require_relative is called in #{$1}"
    end
    #options[:relative] = File.dirname(file)
    absolute = File.expand_path(feature, File.dirname(file))
    require_without_callback absolute
  )

  if result
    Kernel.required_relative(feature)
    Kernel.backloaded(feature, :require=>true, :load=>false, :relative=>File.dirname(file))
  end

  result
end
require_relative_without_callback(feature)

Alias original Kernel.require_relative method.

Alias for: require_relative
require_without_callback(feature)

Alias original Kernel.require method.

Alias for: require

Private Instance Methods

load(path, wrap=nil) click to toggle source

Redefine Kernel#load with callback.

# File lib/backload/load.rb, line 20
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
Also aliased as: load_without_callback
load_without_callback(path, wrap=nil)

Alias original Kernel#load method.

Alias for: load
require(feature, options=nil) click to toggle source

Redefine Kernel#require with callback.

# File lib/backload/require.rb, line 20
def require(feature, options=nil)
  result = require_without_callback(feature)

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

  result
end
Also aliased as: require_without_callback
require_relative(feature) click to toggle source

Redefine Kernel#require_relative with callback.

@todo It would nice if the ‘:relative` option were set to the

realtive path, but that would require `Binding.of_caller`.
# File lib/backload/require_relative.rb, line 26
def require_relative(feature)
  #result = require_relative_without_callback(feature)

  ## We have to reimplement #require_relative instead of calling
  ## the alias to ensure the proper path is used. (*sad*)
  result = (
    c = caller.first
    fail "Can't parse #{c}" unless c.rindex(/:\d+(:in `.*')?$/)
    file = $` # File.dirname(c)
    if /\A\((.*)\)/ =~ file # eval, etc.
      raise LoadError, "require_relative is called in #{$1}"
    end
    #options[:relative] = File.dirname(file)
    absolute = File.expand_path(feature, File.dirname(file))
    require_without_callback(absolute)
  )

  if result
    Kernel.required_relative(feature)
    Kernel.backloaded(feature, :require=>true, :load=>false, :relative=>File.dirname(file))
  end

  result
end
require_relative_without_callback(feature)

Alias original Kernel#require_relative method.

Alias for: require_relative
require_without_callback(feature, options=nil)

Alias original Kernel#require method.

Alias for: require