in doc-architect/doc-architect-core/src/main/java/com/docarchitect/core/scanner/impl/ruby/BundlerDependencyScanner.java [276:325]
private Map<String, GemInfo> parseGemfile(String content) {
Map<String, GemInfo> gems = new HashMap<>();
String[] lines = content.split("\n");
String currentScope = SCOPE_COMPILE;
int groupDepth = 0;
for (String line : lines) {
String trimmedLine = line.trim();
// Skip comments and empty lines
if (trimmedLine.isEmpty() || trimmedLine.startsWith("#")) {
continue;
}
// Check for group start
Matcher groupStartMatcher = GROUP_START_PATTERN.matcher(line);
if (groupStartMatcher.find()) {
String groupDef = groupStartMatcher.group(1);
currentScope = determineScope(groupDef);
groupDepth++;
continue;
}
// Check for group end
if (GROUP_END_PATTERN.matcher(trimmedLine).matches() && groupDepth > 0) {
groupDepth--;
if (groupDepth == 0) {
currentScope = SCOPE_COMPILE;
}
continue;
}
// Parse gem declaration
Matcher gemMatcher = GEM_PATTERN.matcher(line);
if (gemMatcher.find()) {
String gemName = gemMatcher.group(1);
String versionConstraint = gemMatcher.group(2);
// Default to any version if not specified
if (versionConstraint == null || versionConstraint.trim().isEmpty()) {
versionConstraint = "*";
}
gems.put(gemName, new GemInfo(versionConstraint, currentScope));
}
}
return gems;
}