diff --git a/docs/config/README.md b/docs/config/README.md index 7eca0305..db61963c 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -2162,7 +2162,7 @@ detect_extensions = [] ## Ruby -The `ruby` module shows the currently installed version of Ruby. +By default the `ruby` module shows the currently installed version of Ruby. The module will be shown if any of the following conditions are met: - The current directory contains a `Gemfile` file @@ -2171,12 +2171,15 @@ The module will be shown if any of the following conditions are met: ### Options -| Option | Default | Description | -| ---------- | ---------------------------------- | ------------------------------------------------ | -| `format` | `"via [$symbol($version )]($style)"` | The format for the module. | -| `symbol` | `"💎 "` | A format string representing the symbol of Ruby. | -| `style` | `"bold red"` | The style for the module. | -| `disabled` | `false` | Disables the `ruby` module. | +| Option | Default | Description | +| ------------------- | ------------------------------------ | ------------------------------------------------ | +| `format` | `"via [$symbol($version )]($style)"` | The format for the module. | +| `symbol` | `"💎 "` | A format string representing the symbol of Ruby. | +| `detect_extensions` | `["rb"]` | Which extensions should trigger this module. | +| `detect_files` | `["Gemfile", ".ruby-version"]` | Which filenames should trigger this module. | +| `detect_folders` | `[]` | Which folders should trigger this module. | +| `style` | `"bold red"` | The style for the module. | +| `disabled` | `false` | Disables the `ruby` module. | ### Variables diff --git a/src/configs/ruby.rs b/src/configs/ruby.rs index af41d513..be262dad 100644 --- a/src/configs/ruby.rs +++ b/src/configs/ruby.rs @@ -8,6 +8,9 @@ pub struct RubyConfig<'a> { pub symbol: &'a str, pub style: &'a str, pub disabled: bool, + pub detect_extensions: Vec<&'a str>, + pub detect_files: Vec<&'a str>, + pub detect_folders: Vec<&'a str>, } impl<'a> RootModuleConfig<'a> for RubyConfig<'a> { @@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for RubyConfig<'a> { symbol: "💎 ", style: "bold red", disabled: false, + detect_extensions: vec!["rb"], + detect_files: vec!["Gemfile", ".ruby-version"], + detect_folders: vec![], } } } diff --git a/src/modules/ruby.rs b/src/modules/ruby.rs index 6772d750..4f7e22eb 100644 --- a/src/modules/ruby.rs +++ b/src/modules/ruby.rs @@ -9,18 +9,20 @@ use crate::formatter::StringFormatter; /// - Current directory contains a `.rb` file /// - Current directory contains a `Gemfile` or `.ruby-version` file pub fn module<'a>(context: &'a Context) -> Option> { + let mut module = context.new_module("ruby"); + let config = RubyConfig::try_load(module.config); + let is_rb_project = context .try_begin_scan()? - .set_files(&["Gemfile", ".ruby-version"]) - .set_extensions(&["rb"]) + .set_files(&config.detect_files) + .set_extensions(&config.detect_extensions) + .set_folders(&config.detect_folders) .is_match(); if !is_rb_project { return None; } - let mut module = context.new_module("ruby"); - let config = RubyConfig::try_load(module.config); let parsed = StringFormatter::new(config.format).and_then(|formatter| { formatter .map_meta(|var, _| match var {