Class: Rfmt::Configuration
- Inherits:
-
Object
- Object
- Rfmt::Configuration
- Defined in:
- lib/rfmt/configuration.rb
Overview
File selection and cache concerns only: formatter settings (indent_width etc.) live in the Rust Config, reached via Rfmt.format(config_path:).
Defined Under Namespace
Classes: ConfigError
Constant Summary collapse
- DEFAULT_CONFIG =
{ 'version' => '1.0', 'include' => ['**/*.rb'], 'exclude' => ['vendor/**/*', 'tmp/**/*', 'node_modules/**/*'] }.freeze
- CONFIG_FILES =
['rfmt.yml', 'rfmt.yaml', '.rfmt.yml', '.rfmt.yaml'].freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
-
.discover ⇒ Object
Discover configuration file in current directory.
Instance Method Summary collapse
-
#files_to_format(base_path: '.') ⇒ Object
Get list of files to format based on include/exclude patterns.
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
21 22 23 |
# File 'lib/rfmt/configuration.rb', line 21 def initialize( = {}) @config = load_configuration() end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
19 20 21 |
# File 'lib/rfmt/configuration.rb', line 19 def config @config end |
Class Method Details
.discover ⇒ Object
Discover configuration file in current directory
26 27 28 29 |
# File 'lib/rfmt/configuration.rb', line 26 def self.discover config_file = CONFIG_FILES.find { |file| File.exist?(file) } config_file ? new(file: config_file) : new end |
Instance Method Details
#files_to_format(base_path: '.') ⇒ Object
Get list of files to format based on include/exclude patterns
32 33 34 35 36 37 38 39 40 |
# File 'lib/rfmt/configuration.rb', line 32 def files_to_format(base_path: '.') include_patterns = @config['include'] exclude_patterns = @config['exclude'] included_files = include_patterns.flat_map { |pattern| Dir.glob(File.join(base_path, pattern)) } excluded_files = exclude_patterns.flat_map { |pattern| Dir.glob(File.join(base_path, pattern)) } (included_files - excluded_files).select { |f| File.file?(f) } end |