File: require_relative_dir.rb

package info (click to toggle)
ruby-backports 3.25.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,912 kB
  • sloc: ruby: 11,759; makefile: 6
file content (18 lines) | stat: -rw-r--r-- 516 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module Backports
  def self.require_relative_dir
    dir = caller.first.split(/\.rb:\d/,2).first
    short_path = dir[/.*(backports\/.*)/, 1] << '/'
    Dir.entries(dir).
        map{|f| Regexp.last_match(1) if /^(.*)\.rb$/ =~ f}.
        compact.
        sort.
        each do |f|
          path = '../../' + short_path + f
          if Kernel.private_method_defined?(:require_relative)
            require_relative path
          else
            require File.expand_path(path)
          end
        end
  end
end