In Files

Class Index [+]

Quicksearch

Subload

TODO convert to yardoc

Constants

VERSION
(Not documented)
MODES

To add modes to subload, simply add them to this hash. Please use the a namespace convention, starting with :projectname_operationdescription.

LONG_UPPER_CONSTS
(Not documented)
TAIL_UPPER_CONSTS
(Not documented)
DOUBLE_UNDERSCORE
(Not documented)
DOUBLE_COLON
(Not documented)
SLASH
(Not documented)

Attributes

default_mode[RW]

Subload defaults to autoload, which is appropriate and performant for single threaded applications and libraries. Setting the default mode will affect all future subloads that do not specify another mode explicitly, proided Subload.override_mode has not been set.

override_mode[RW]

Subload defaults to autoload, which is appropriate and performant for single threaded applications and libraries. Sometimes users may want to switch to eager loading or some other loading mechanism forcefully. Override mode should not be set in normal library code, but should be reserved for application code only. It may be acceptable for use in appropriate locations in frameworks.

Public Class Methods

to_path(s) click to toggle source

Subloads snake_case method, this is very similar to that of facets, rails, and merb, but potentially has minor differences.

# File lib/subload.rb, line 75
  def self.to_path(s)
    # similar to facets/string/pathize, only supports TCPServer, etc.
    s = s.to_s.dup # We're modifying, lets be careful
    s.gsub!(*LONG_UPPER_CONSTS)
    s.gsub!(*TAIL_UPPER_CONSTS)
    s.gsub!(DOUBLE_UNDERSCORE, SLASH)
    s.gsub!(DOUBLE_COLON, SLASH)
    s.downcase!
    s
  end

Public Instance Methods

subload(symbol, options = {}) click to toggle source

Load the given constant name from the path corresponding to the conventional mapping of the class name underscored. Example:

 class A
  subload :B # performs A.autoload(:B, 'a/b')
 end

You can overload various operation styles in subload using the options hash:

  • :path - explicitly alter the path that will be loaded, this is passed on unmodified.
  • :mode - explicitly override the loading mode. N.B. Subload.override_mode takes precidence over this.
  • :expand_path - when set to true, the path will be expanded before being passed on to the loading mechanism.

For custom loading mechanisms, further options are passed on, as such, you may find other behaviors if subload is being used inside a framework.

# File lib/subload.rb, line 57
  def subload(symbol, options = {})
    sub_path, mode = *options.values_at(:path, :mode)
    klass = self.instance_of?(Class) || self.instance_of?(Module)
    klass = klass ? self.__name__ : self.class.__name__
    path = File.join(sub_path || Subload.to_path("#{klass}::#{symbol}"))
    path = File.expand_path(path) if options[:expand_path]
    $stdout.puts [:subload, symbol, path, mode].inspect if $DEBUG
    subload_with(mode)[self, symbol, path, options]
  end
subload_with(mode = nil) click to toggle source

Sets the subload mode locally for the current class. This is how one would use a custom loading mode

# File lib/subload.rb, line 31
  def subload_with(mode = nil)
    @_subload_mode = mode unless mode.nil?
    MODES[
      Subload.override_mode ||
      (defined?(@_subload_mode) && @_subload_mode) ||
      Subload.default_mode
    ]
  end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.