Skip to content

Commit 7dc5f95

Browse files
committed
Validate core library path format and simplify copy logic
Raise an exception when a load path does not match the expected core library directories via RUBY_LIBRARY_PATH_REGEX. Remove the old match block and replace it with a direct iteration over `path.find`, copying each file into the correct relative subdirectory. This improves error detection and streamlines the copy workflow.
1 parent 279cd4f commit 7dc5f95

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/ocran/direction.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,13 @@ def construct(builder)
211211
say "Will include all ruby core libraries"
212212
all_core_dir.each do |path|
213213
# Match the load path against standard library, site_ruby, and vendor_ruby paths
214-
path.to_posix.match(RUBY_LIBRARY_PATH_REGEX) do |m|
215-
subdir = m[1]
216-
path.find.each do |src|
217-
next if src.directory?
218-
builder.copy_to_lib(src, Pathname(subdir) / src.relative_path_from(path))
219-
end
214+
unless (subdir = path.to_posix.match(RUBY_LIBRARY_PATH_REGEX)&.[](1))
215+
raise "Unexpected library path format (does not match core dirs): #{path}"
216+
end
217+
path.find.each do |src|
218+
next if src.directory?
219+
a = Pathname(subdir) / src.relative_path_from(path)
220+
builder.copy_to_lib(src, Pathname(subdir) / src.relative_path_from(path))
220221
end
221222
end
222223
end

0 commit comments

Comments
 (0)