Module: ActiveSupport::Dependencies
- Defined in:
- lib/rails/decorators/active_support.rb
Defined Under Namespace
Modules: Loadable
Class Method Summary collapse
-
.load_file(path, const_paths = loadable_constants_for_path(path)) ⇒ Object
Monkey patched because Rails appends a ‘.rb` to all files it tries to load with `require_dependency`.
Class Method Details
.load_file(path, const_paths = loadable_constants_for_path(path)) ⇒ Object
Monkey patched because Rails appends a ‘.rb` to all files it tries to load with `require_dependency`. It does this for a good reason: both the oob `require` and oob `load` provided by Ruby will accept a path ending with `.rb`. But in our case, we want to ensure that decorators are loaded with `load` since `require` doesn’t accept files that don’t end with ‘.rb`.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rails/decorators/active_support.rb', line 33 def self.load_file(path, const_paths = loadable_constants_for_path(path)) path = path.gsub(/\.rb\z/, '') if path.end_with?(".#{Rails::Decorators.extension}.rb") # # Below this copy/pasted from Rails :( # const_paths = [const_paths].compact unless const_paths.is_a? Array parent_paths = const_paths.collect { |const_path| const_path[/.*(?=::)/] || ::Object } result = nil newly_defined_paths = new_constants_in(*parent_paths) do result = Kernel.load path end autoloaded_constants.concat newly_defined_paths unless load_once_path?(path) autoloaded_constants.uniq! result end |