Skip to content

Commit 4e8fe3b

Browse files
authored
Merge pull request #827 from Shopify/index-all-ruby-like-files
Indexing `.rake` and `.ru` files
2 parents adb18d8 + e597363 commit 4e8fe3b

3 files changed

Lines changed: 41 additions & 4 deletions

File tree

lib/rubydex/graph.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class Graph
1717
"tmp",
1818
].freeze
1919

20+
INDEXABLE_EXTENSIONS = [".rb", ".rake", ".rbs", ".ru"].freeze
21+
2022
#: String
2123
attr_accessor :workspace_path
2224

@@ -45,7 +47,7 @@ def workspace_paths
4547

4648
if File.directory?(full_path)
4749
paths << full_path unless IGNORED_DIRECTORIES.include?(entry)
48-
elsif File.extname(entry) == ".rb"
50+
elsif INDEXABLE_EXTENSIONS.include?(File.extname(entry))
4951
paths << full_path
5052
end
5153
end

rust/rubydex/src/listing.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ impl FileDiscoveryJob {
3838
}
3939
}
4040

41+
fn is_indexable_file(path: &Path) -> bool {
42+
path.extension()
43+
.is_some_and(|ext| ext == "rb" || ext == "rake" || ext == "rbs" || ext == "ru")
44+
}
45+
4146
impl FileDiscoveryJob {
4247
fn handle_file(&self, path: &Path) {
43-
if path.extension().is_some_and(|ext| ext == "rb" || ext == "rbs") {
48+
if is_indexable_file(path) {
4449
self.paths_tx
4550
.send(path.to_path_buf())
4651
.expect("file receiver dropped before run completion");
@@ -266,22 +271,28 @@ mod tests {
266271
}
267272

268273
#[test]
269-
fn collect_rbs_files() {
274+
fn collect_indexable_files() {
270275
let context = Context::new();
271276
let ruby_file = PathBuf::from("lib").join("foo.rb");
277+
let rake_file = PathBuf::from("lib").join("task.rake");
272278
let rbs_file = PathBuf::from("sig").join("foo.rbs");
279+
let rack_file = PathBuf::from("config.ru");
273280
let txt_file = PathBuf::from("lib").join("notes.txt");
274281
context.touch(&ruby_file);
282+
context.touch(&rake_file);
275283
context.touch(&rbs_file);
284+
context.touch(&rack_file);
276285
context.touch(&txt_file);
277286

278-
let (files, errors) = collect_document_paths(&context, &["lib", "sig"]);
287+
let (files, errors) = collect_document_paths(&context, &["lib", "sig", "config.ru"]);
279288

280289
assert!(errors.is_empty());
281290

282291
assert_eq!(
283292
[
293+
rack_file.to_str().unwrap().to_string(),
284294
ruby_file.to_str().unwrap().to_string(),
295+
rake_file.to_str().unwrap().to_string(),
285296
rbs_file.to_str().unwrap().to_string(),
286297
],
287298
files.as_slice()

test/graph_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ def test_indexing_context_files
2323
end
2424
end
2525

26+
def test_indexing_ruby_file_extensions
27+
with_context do |context|
28+
context.write!("foo.rb", "class Foo; end")
29+
context.write!("task.rake", "class Task; end")
30+
context.write!("config.ru", "class Config; end")
31+
context.write!("notes.txt", "class Notes; end")
32+
33+
graph = Rubydex::Graph.new
34+
assert_empty(graph.index_all([context.absolute_path]))
35+
graph.resolve
36+
37+
refute_nil(graph["Foo"])
38+
refute_nil(graph["Task"])
39+
refute_nil(graph["Config"])
40+
assert_nil(graph["Notes"])
41+
end
42+
end
43+
2644
def test_indexing_invalid_file_paths
2745
graph = Rubydex::Graph.new
2846

@@ -601,6 +619,9 @@ def test_workspace_paths
601619
context.write!(".git/config", "")
602620
context.write!("node_modules/pkg/index.js", "")
603621
context.write!("top_level.rb", "class TopLevel; end")
622+
context.write!("top_level.rake", "class TopLevelRake; end")
623+
context.write!("top_level.rbs", "class TopLevelRbs; end")
624+
context.write!("config.ru", "class ConfigRu; end")
604625

605626
graph = Rubydex::Graph.new(workspace_path: context.absolute_path)
606627
paths = graph.workspace_paths
@@ -615,6 +636,9 @@ def test_workspace_paths
615636

616637
# Includes the top level files
617638
assert_includes(paths, context.absolute_path_to("top_level.rb"))
639+
assert_includes(paths, context.absolute_path_to("top_level.rake"))
640+
assert_includes(paths, context.absolute_path_to("top_level.rbs"))
641+
assert_includes(paths, context.absolute_path_to("config.ru"))
618642

619643
# Includes gem dependency paths from Bundler
620644
gem_require_paths = Bundler.locked_gems.specs.flat_map do |lazy_spec|

0 commit comments

Comments
 (0)