probe_code/language/
ruby.rs1use super::language_trait::LanguageImpl;
2use tree_sitter::{Language as TSLanguage, Node};
3
4pub struct RubyLanguage;
6
7impl Default for RubyLanguage {
8 fn default() -> Self {
9 Self::new()
10 }
11}
12
13impl RubyLanguage {
14 pub fn new() -> Self {
15 RubyLanguage
16 }
17}
18
19impl LanguageImpl for RubyLanguage {
20 fn get_tree_sitter_language(&self) -> TSLanguage {
21 tree_sitter_ruby::LANGUAGE.into()
22 }
23
24 fn get_extension(&self) -> &'static str {
25 "rb"
26 }
27
28 fn is_acceptable_parent(&self, node: &Node) -> bool {
29 matches!(
30 node.kind(),
31 "method" | "class" | "module" | "singleton_method"
32 )
33 }
34
35 fn is_test_node(&self, node: &Node, source: &[u8]) -> bool {
36 let debug_mode = std::env::var("DEBUG").unwrap_or_default() == "1";
37 let node_type = node.kind();
38
39 if node_type == "method" {
41 let mut cursor = node.walk();
42 for child in node.children(&mut cursor) {
43 if child.kind() == "identifier" {
44 let name = child.utf8_text(source).unwrap_or("");
45 if name.starts_with("test_") {
46 if debug_mode {
47 println!("DEBUG: Test node detected (Ruby): test_ method");
48 }
49 return true;
50 }
51 }
52 }
53 } else if node_type == "call" {
54 let mut cursor = node.walk();
55 for child in node.children(&mut cursor) {
56 if child.kind() == "identifier" {
57 let name = child.utf8_text(source).unwrap_or("");
58 if name == "describe" || name == "it" || name == "context" || name == "specify"
59 {
60 if debug_mode {
61 println!("DEBUG: Test node detected (Ruby): {name} block");
62 }
63 return true;
64 }
65 }
66 }
67 }
68
69 false
70 }
71}