Class: Dependencies::ConstantLoadPath

Inherits:
Object
  • Object
show all
Defined in:
lib/active_support/dependencies.rb

Overview

This object defines a path from which Constants can be loaded.

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ ConstantLoadPath

Create a new load path with the filesystem path



131
# File 'lib/active_support/dependencies.rb', line 131

def initialize(root) @root = root end

Instance Method Details

#const_name_to_file_name(name) ⇒ Object



149
150
151
# File 'lib/active_support/dependencies.rb', line 149

def const_name_to_file_name(name)
  name.to_s.underscore + '.rb'
end

#const_name_to_module_name(name) ⇒ Object



153
154
155
# File 'lib/active_support/dependencies.rb', line 153

def const_name_to_module_name(name)
  name.to_s.underscore
end

#filesystem_path(path, allow_module = true) ⇒ Object

Return nil if the path does not exist, or the path to a directory if the path leads to a module, or the path to a file if it leads to an object.



135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/active_support/dependencies.rb', line 135

def filesystem_path(path, allow_module=true)
  fs_path = [@root]
  fs_path += path[0..-2].collect {|name| const_name_to_module_name name}

  if allow_module
    result = File.join(fs_path, const_name_to_module_name(path.last))
    return result if File.directory? result # Return the module path if one exists
  end

  result = File.join(fs_path, const_name_to_file_name(path.last))

  return File.file?(result) ? result : nil
end