Skip to main content

sherlock_io/patterns/
ruby.rs

1use regex::Regex;
2
3pub struct RubyPatterns {
4    external_patterns: Vec<Regex>,
5    cache_patterns: Vec<Regex>,
6    extensions: Vec<String>,
7}
8
9impl RubyPatterns {
10    pub fn new() -> Self {
11        let external_patterns = vec![
12            // Gem system
13            Regex::new(r"\.bundle/").unwrap(),
14            Regex::new(r"vendor/bundle/").unwrap(),
15            Regex::new(r"\.gem$").unwrap(),
16            Regex::new(r"Gemfile\.lock").unwrap(),
17            
18            // RubyGems
19            Regex::new(r"\.gem/").unwrap(),
20            Regex::new(r"gems/").unwrap(),
21            
22            // Rails specific
23            Regex::new(r"log/").unwrap(),
24            Regex::new(r"tmp/").unwrap(),
25            Regex::new(r"storage/").unwrap(),
26            Regex::new(r"public/assets/").unwrap(),
27            Regex::new(r"public/packs/").unwrap(),
28            Regex::new(r"public/uploads/").unwrap(),
29            
30            // Coverage
31            Regex::new(r"coverage/").unwrap(),
32            
33            // RSpec
34            Regex::new(r"spec/reports/").unwrap(),
35            
36            // Yard documentation
37            Regex::new(r"\.yardoc/").unwrap(),
38            Regex::new(r"doc/").unwrap(),
39            
40            // Capistrano
41            Regex::new(r"\.capistrano/").unwrap(),
42            
43            // Byebug
44            Regex::new(r"\.byebug_history").unwrap(),
45            
46            // IRB
47            Regex::new(r"\.irb_history").unwrap(),
48            
49            // Pry
50            Regex::new(r"\.pry_history").unwrap(),
51            
52            // RVM
53            Regex::new(r"\.rvmrc").unwrap(),
54            
55            // rbenv
56            Regex::new(r"\.ruby-version").unwrap(),
57            Regex::new(r"\.ruby-gemset").unwrap(),
58            
59            // Pow
60            Regex::new(r"\.powrc").unwrap(),
61            Regex::new(r"\.powder").unwrap(),
62            
63            // Sass cache
64            Regex::new(r"\.sass-cache/").unwrap(),
65            
66            // Capybara
67            Regex::new(r"capybara-").unwrap(),
68            
69            // Spring
70            Regex::new(r"\.spring/").unwrap(),
71            
72            // Bootsnap
73            Regex::new(r"\.bootsnap-").unwrap(),
74            
75            // Listen
76            Regex::new(r"\.listen_test").unwrap(),
77            
78            // Rerun
79            Regex::new(r"\.rerun\.pid").unwrap(),
80            
81            // Spork
82            Regex::new(r"\.spork\.pid").unwrap(),
83            
84            // Guard
85            Regex::new(r"\.guard_history").unwrap(),
86            
87            // Solr
88            Regex::new(r"solr/").unwrap(),
89            
90            // Elasticsearch
91            Regex::new(r"elasticsearch/").unwrap(),
92            
93            // Redis
94            Regex::new(r"dump\.rdb").unwrap(),
95            
96            // Sidekiq
97            Regex::new(r"sidekiq\.pid").unwrap(),
98            
99            // Puma
100            Regex::new(r"puma\.pid").unwrap(),
101            
102            // Unicorn
103            Regex::new(r"unicorn\.pid").unwrap(),
104            
105            // Thin
106            Regex::new(r"thin\.pid").unwrap(),
107            
108            // Passenger
109            Regex::new(r"passenger\.").unwrap(),
110            
111            // Foreman
112            Regex::new(r"\.foreman").unwrap(),
113            
114            // Heroku
115            Regex::new(r"\.slugignore").unwrap(),
116            
117            // Vagrant
118            Regex::new(r"\.vagrant/").unwrap(),
119            
120            // Docker
121            Regex::new(r"\.dockerignore").unwrap(),
122            
123            // IDE files
124            Regex::new(r"\.vscode/").unwrap(),
125            Regex::new(r"\.idea/").unwrap(),
126            Regex::new(r"\.sublime-").unwrap(),
127            
128            // OS files
129            Regex::new(r"\.DS_Store").unwrap(),
130            Regex::new(r"Thumbs\.db").unwrap(),
131            
132            // Backup files
133            Regex::new(r"\.bak$").unwrap(),
134            Regex::new(r"\.swp$").unwrap(),
135            Regex::new(r"\.swo$").unwrap(),
136            Regex::new(r"~$").unwrap(),
137        ];
138
139        let cache_patterns = vec![
140            // Bundler cache
141            Regex::new(r"\.bundle/").unwrap(),
142            Regex::new(r"vendor/bundle/").unwrap(),
143            
144            // Gem cache
145            Regex::new(r"\.gem/").unwrap(),
146            
147            // Rails cache
148            Regex::new(r"tmp/cache/").unwrap(),
149            Regex::new(r"tmp/pids/").unwrap(),
150            Regex::new(r"tmp/sessions/").unwrap(),
151            Regex::new(r"tmp/sockets/").unwrap(),
152            
153            // Asset cache
154            Regex::new(r"public/assets/").unwrap(),
155            Regex::new(r"public/packs/").unwrap(),
156            
157            // Test cache
158            Regex::new(r"coverage/").unwrap(),
159            Regex::new(r"spec/reports/").unwrap(),
160            
161            // Documentation cache
162            Regex::new(r"\.yardoc/").unwrap(),
163            Regex::new(r"doc/").unwrap(),
164            
165            // Sass cache
166            Regex::new(r"\.sass-cache/").unwrap(),
167            
168            // Spring cache
169            Regex::new(r"\.spring/").unwrap(),
170            
171            // Bootsnap cache
172            Regex::new(r"\.bootsnap-").unwrap(),
173            
174            // Log files
175            Regex::new(r"log/").unwrap(),
176            
177            // Temporary files
178            Regex::new(r"tmp/").unwrap(),
179            
180            // IDE caches
181            Regex::new(r"\.vscode/").unwrap(),
182            Regex::new(r"\.idea/").unwrap(),
183            
184            // OS caches
185            Regex::new(r"\.DS_Store").unwrap(),
186            Regex::new(r"Thumbs\.db").unwrap(),
187            
188            // Editor files
189            Regex::new(r"\.swp$").unwrap(),
190            Regex::new(r"\.swo$").unwrap(),
191            Regex::new(r"~$").unwrap(),
192        ];
193
194        let extensions = vec![
195            // Ruby files
196            "rb".to_string(), "rbw".to_string(),
197            
198            // Rake files
199            "rake".to_string(),
200            
201            // Gemspec files
202            "gemspec".to_string(),
203            
204            // Rackup files
205            "ru".to_string(),
206            
207            // ERB templates
208            "erb".to_string(), "rhtml".to_string(),
209            
210            // Haml templates
211            "haml".to_string(),
212            
213            // Slim templates
214            "slim".to_string(),
215            
216            // Liquid templates
217            "liquid".to_string(),
218            
219            // RDoc
220            "rdoc".to_string(),
221            
222            // YAML (common in Ruby projects)
223            "yml".to_string(), "yaml".to_string(),
224            
225            // JSON (common in Ruby projects)
226            "json".to_string(),
227            
228            // Markdown
229            "md".to_string(), "markdown".to_string(),
230            
231            // Ruby scripts
232            "rbx".to_string(),
233            
234            // Thor
235            "thor".to_string(),
236            
237            // Capfile
238            "cap".to_string(),
239            
240            // Prawn
241            "prawn".to_string(),
242            
243            // Builder
244            "builder".to_string(),
245            
246            // RABL
247            "rabl".to_string(),
248            
249            // JBuilder
250            "jbuilder".to_string(),
251        ];
252
253        Self {
254            external_patterns,
255            cache_patterns,
256            extensions,
257        }
258    }
259
260    pub fn get_external_patterns(&self) -> &[Regex] {
261        &self.external_patterns
262    }
263
264    pub fn get_cache_patterns(&self) -> &[Regex] {
265        &self.cache_patterns
266    }
267
268    pub fn get_extensions(&self) -> &[String] {
269        &self.extensions
270    }
271
272    pub fn get_script_names() -> Vec<&'static str> {
273        vec![
274            // Core Ruby files
275            "Gemfile", "Gemfile.lock", "*.gemspec", "Rakefile",
276            "config.ru", "Capfile", "Guardfile", "Procfile",
277            
278            // Rails files
279            "application.rb", "environment.rb", "boot.rb",
280            "routes.rb", "database.yml", "secrets.yml",
281            "application.yml", "cable.yml", "storage.yml",
282            
283            // Configuration
284            "config/application.rb", "config/environment.rb",
285            "config/boot.rb", "config/routes.rb",
286            "config/database.yml", "config/secrets.yml",
287            
288            // Environments
289            "config/environments/development.rb",
290            "config/environments/production.rb",
291            "config/environments/test.rb",
292            
293            // Initializers
294            "config/initializers/", "config/locales/",
295            
296            // Database
297            "db/schema.rb", "db/seeds.rb", "db/migrate/",
298            
299            // Testing
300            "spec/spec_helper.rb", "spec/rails_helper.rb",
301            "test/test_helper.rb", ".rspec", ".rspec-local",
302            
303            // Coverage
304            ".simplecov", "coverage/",
305            
306            // Deployment
307            "config/deploy.rb", "config/deploy/",
308            "Capfile", ".caprc",
309            
310            // Bundler
311            ".bundle/config", "vendor/bundle/",
312            
313            // Version managers
314            ".ruby-version", ".ruby-gemset", ".rvmrc",
315            
316            // Documentation
317            ".yardopts", ".document", "README.md",
318            "CHANGELOG.md", "LICENSE", "CONTRIBUTING.md",
319            
320            // CI/CD
321            ".github/workflows/ruby.yml", ".travis.yml",
322            ".gitlab-ci.yml", "circle.yml", "appveyor.yml",
323            
324            // Code quality
325            ".rubocop.yml", ".reek.yml", ".inch.yml",
326            ".codeclimate.yml", ".hound.yml",
327            
328            // Docker
329            "Dockerfile", "docker-compose.yml", ".dockerignore",
330            
331            // Heroku
332            ".slugignore", "app.json", "Procfile.dev",
333            
334            // Environment
335            ".env", ".env.local", ".env.development",
336            ".env.production", ".env.test", ".env.example",
337            
338            // Editors
339            ".vscode/", ".idea/", ".sublime-project",
340            
341            // Git
342            ".gitignore", ".gitattributes", ".gitmodules",
343            
344            // Package managers
345            "yarn.lock", "package.json", "package-lock.json",
346            
347            // Asset pipeline
348            "app/assets/", "vendor/assets/", "lib/assets/",
349            
350            // Views
351            "app/views/", "app/helpers/",
352            
353            // Controllers
354            "app/controllers/", "app/models/",
355            
356            // Services
357            "app/services/", "app/jobs/", "app/mailers/",
358            
359            // Concerns
360            "app/concerns/", "app/decorators/",
361            
362            // Policies
363            "app/policies/", "app/validators/",
364            
365            // Serializers
366            "app/serializers/", "app/presenters/",
367            
368            // Workers
369            "app/workers/", "app/channels/",
370            
371            // Libraries
372            "lib/", "lib/tasks/", "lib/generators/",
373            
374            // Engines
375            "engines/", "gems/", "vendor/gems/",
376            
377            // Public
378            "public/", "public/assets/", "public/uploads/",
379            
380            // Storage
381            "storage/", "tmp/storage/",
382            
383            // Logs
384            "log/", "tmp/",
385            
386            // Scripts
387            "bin/", "script/", "exe/",
388            
389            // Locale
390            "config/locales/", "locale/",
391            
392            // Fixtures
393            "spec/fixtures/", "test/fixtures/",
394            
395            // Factories
396            "spec/factories/", "test/factories/",
397            
398            // Support
399            "spec/support/", "test/support/",
400            
401            // Features
402            "features/", "spec/features/",
403            
404            // Integration
405            "spec/integration/", "test/integration/",
406            
407            // System
408            "spec/system/", "test/system/",
409            
410            // Requests
411            "spec/requests/", "test/requests/",
412            
413            // Controllers
414            "spec/controllers/", "test/controllers/",
415            
416            // Models
417            "spec/models/", "test/models/",
418            
419            // Views
420            "spec/views/", "test/views/",
421            
422            // Helpers
423            "spec/helpers/", "test/helpers/",
424            
425            // Mailers
426            "spec/mailers/", "test/mailers/",
427            
428            // Jobs
429            "spec/jobs/", "test/jobs/",
430            
431            // Channels
432            "spec/channels/", "test/channels/",
433            
434            // Routing
435            "spec/routing/", "test/routing/",
436        ]
437    }
438}