Method: Motion::Require.dependencies_for

Defined in:
lib/motion-require.rb

.dependencies_for(files) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/motion-require.rb', line 53

def dependencies_for(files)
  dependencies = {}
  files.each do |file_path|
    requires = requires_in(file_path)
    if !requires.empty?
      dependencies[file_path] = requires.map { |required|
        required_path = resolve_path(file_path, required)
        if !File.exist?(required_path) && File.extname(required) != ".rb"
          required_path += ".rb"
        end

        if !File.exist?(required_path)
          # TODO: Report line number of failing require
          raise LoadError, "ERROR! In `#{file_path}', could not require `#{required}', file not found."
        end

        required_path
      }
      dependencies[file_path].unshift ext_file
    end
  end
  dependencies
end