Daniel Novotny 60d6edf
From eebad924e62b678a54d3af05a12da2a929f5d918 Mon Sep 17 00:00:00 2001
Daniel Novotny 60d6edf
From: Lubomir Rintel <lkundrak@v3.sk>
Daniel Novotny 60d6edf
Date: Fri, 5 Feb 2010 13:19:48 +0100
Daniel Novotny 60d6edf
Subject: [PATCH] Add matches for ruby modules
Daniel Novotny 60d6edf
Daniel Novotny 60d6edf
Similar to what's already done for Perl. Existing rules only match shebangs,
Daniel Novotny 60d6edf
which is not useful in most cases. This was tested to yield no false
Daniel Novotny 60d6edf
positives when run against every perl and python source file I could find
Daniel Novotny 60d6edf
on my system (260 CPAN modules and 59 Python modules). Produces a couple
Daniel Novotny 60d6edf
of false negatives for a couple of files from 30 Ruby gems I have
Daniel Novotny 60d6edf
installed, but is still an improvement over existing rules. (Ruby is
Daniel Novotny 60d6edf
used to construct DSLs quite often, it would be really tricky to match
Daniel Novotny 60d6edf
those).
Daniel Novotny 60d6edf
---
Daniel Novotny 60d6edf
 magic/Magdir/ruby |   12 ++++++++++++
Daniel Novotny 60d6edf
 1 files changed, 12 insertions(+), 0 deletions(-)
Daniel Novotny 60d6edf
Daniel Novotny 60d6edf
diff --git a/magic/Magdir/ruby b/magic/Magdir/ruby
Daniel Novotny 60d6edf
index 7030295..be1786c 100644
Daniel Novotny 60d6edf
--- a/magic/Magdir/ruby
Daniel Novotny 60d6edf
+++ b/magic/Magdir/ruby
Daniel Novotny 60d6edf
@@ -14,3 +14,15 @@
Daniel Novotny 60d6edf
 !:mime text/x-ruby
Daniel Novotny 60d6edf
 0	search/1	#!\ /usr/bin/env\ ruby	Ruby script text executable
Daniel Novotny 60d6edf
 !:mime text/x-ruby
Daniel Novotny 60d6edf
+
Daniel Novotny 60d6edf
+# What looks like ruby, but does not have a shebang
Daniel Novotny 60d6edf
+# (modules and such)
Daniel Novotny 60d6edf
+# From: Lubomir Rintel <lkundrak@v3.sk>
Daniel Novotny 60d6edf
+0	regex		\^[\ \t]*require[\ \t]'[A-Za-z_\/]+'
Daniel Novotny 60d6edf
+>0	regex		include\ [A-Z]|def\ [a-z]|\ do$
Daniel Novotny 60d6edf
+>>0	regex		\^[\ \t]*end([\ \t]*[;#].*)?$		Ruby script text
Daniel Novotny 60d6edf
+!:mime	text/x-ruby
Daniel Novotny 60d6edf
+0	regex		\^[\ \t]*(class|module)[\ \t][A-Z]
Daniel Novotny 60d6edf
+>0	regex		(modul|includ)e\ [A-Z]|def\ [a-z]
Daniel Novotny 60d6edf
+>>0	regex		\^[\ \t]*end([\ \t]*[;#].*)?$		Ruby module source text
Daniel Novotny 60d6edf
+!:mime	text/x-ruby
Daniel Novotny 60d6edf
-- 
Daniel Novotny 60d6edf
1.6.6
Daniel Novotny 60d6edf