Class: Autoloaded::LoadPathedDirectory Private

Inherits:
Object
  • Object
show all
Defined in:
lib/autoloaded/load_pathed_directory.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Enumerates the source files in a directory, relativizing their paths using the Ruby load path.

Since:

  • 1.3

Constant Summary collapse

SOURCE_FILE_EXTENSION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The file extension of source files.

Since:

  • 1.3

'.rb'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ LoadPathedDirectory

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Constructs a new LoadPathedDirectory with the specified path.

Parameters:

  • path (String)

    the value of #path

Raises:

  • (ArgumentError)

    path is nil or a relative path

Since:

  • 1.3



43
44
45
46
47
48
49
50
# File 'lib/autoloaded/load_pathed_directory.rb', line 43

def initialize(path)
  raise ::ArgumentError, "can't be nil" if path.nil?

  @path = path.dup.freeze
  if ::Pathname.new(@path).relative?
    raise ::ArgumentError, "can't be relative"
  end
end

Instance Attribute Details

#pathString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The full path of a source directory.

Returns:

  • (String)

    a directory path

Since:

  • 1.3



36
37
38
# File 'lib/autoloaded/load_pathed_directory.rb', line 36

def path
  @path
end

Instance Method Details

#each_source_filename {|String| ... } ⇒ LoadPathedDirectory

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Enumerates the source files in #path, relativizing their paths if possible using the longest applicable entry in the Ruby load path (that is, $:). File names are rendered without SOURCE_FILE_EXTENSION. Yielded paths are guaranteed usable in require statements unless elements of the Ruby load path are removed or changed.

Yields:

  • (String)

    each source file in #path, formatted for use in require statements

Returns:

See Also:

Since:

  • 1.3



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/autoloaded/load_pathed_directory.rb', line 65

def each_source_filename
  if (ruby_load_path = closest_ruby_load_path)
    ::Dir.chdir ruby_load_path do
      glob = self.class.join(path_from(ruby_load_path),
                             "*#{SOURCE_FILE_EXTENSION}")
      ::Dir.glob glob do |file|
        yield without_source_file_extension(file)
      end
    end
  else
    glob = self.class.join(path, "*#{SOURCE_FILE_EXTENSION}")
    ::Dir.glob glob do |file|
      yield without_source_file_extension(file)
    end
  end

  self
end