Sha256: 2052dc29233053e185d558c628acfe18f88cf8dc5ed5d25550f8293f5f50c938
Contents?: true
Size: 1.78 KB
Versions: 7
Compression:
Stored size: 1.78 KB
Contents
# frozen_string_literal: true BASE_FOLDER_PATH = 'rspec' def directories_in(root) Dir.entries(root).sort.select do |entry| fully_qualified_entry = File.join(root, entry) File.directory?(fully_qualified_entry) && !['.', '..'].include?(entry.to_s) end end def files_in(root) Dir.entries(root).sort.reject do |entry| fully_qualified_entry = File.join(root, entry) File.directory?(fully_qualified_entry) || entry.to_s == 'all.rb' || entry[-3..-1] != '.rb' end end def recursive_files_in(root) full_paths = Dir.glob(File.join(root, '**', '*')).sort.reject do |entry| fully_qualified_entry = File.join(root, entry) File.directory?(fully_qualified_entry) || entry[-7..-1] == '/all.rb' || entry[-3..-1] != '.rb' end remove_path = root.split('/')[0..-2].join('/') + '/' full_paths.map { |full_path| full_path.gsub(remove_path, '') } end def write_require_file(root, require_directories, require_files) require_file_path = File.join(root, 'all.rb') File.open(require_file_path, 'w') do |file| file.write("# frozen_string_literal: true\n\n") file.write("# THIS FILE IS AUTOGENERATED AND SHOULD NOT BE MANUALLY MODIFIED\n\n") require_directories.each do |require_directory| file.write("require '#{BASE_FOLDER_PATH}/#{require_directory}/all'\n") end file.write("\n") unless require_directories.empty? require_files.each { |require_file| file.write("require '#{BASE_FOLDER_PATH}/#{require_file[0..-4]}'\n") } end end root = File.join(__dir__, 'lib', BASE_FOLDER_PATH) directories = directories_in(root) write_require_file(root, directories, files_in(root)) directories.each do |directory| fully_qualified_directory = File.join(root, directory) write_require_file(fully_qualified_directory, [], recursive_files_in(fully_qualified_directory)) end
Version data entries
7 entries across 7 versions & 1 rubygems