Class: Collie::Config
- Inherits:
-
Object
- Object
- Collie::Config
- Defined in:
- lib/collie/config.rb
Overview
Configuration management
Constant Summary collapse
- DEFAULT_CONFIG =
{ "rules" => {}, "formatter" => { "indent_size" => 2, "align_tokens" => true, "align_alternatives" => true, "blank_lines_around_sections" => 1, "max_line_length" => 120 }, "include" => ["**/*.y"], "exclude" => ["vendor/**/*", "tmp/**/*"] }.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #excluded_patterns ⇒ Object
- #formatter_options ⇒ Object
- #included_patterns ⇒ Object
-
#initialize(config_path = nil) ⇒ Config
constructor
A new instance of Config.
- #rule_config(rule_name) ⇒ Object
- #rule_enabled?(rule_name) ⇒ Boolean
Constructor Details
#initialize(config_path = nil) ⇒ Config
Returns a new instance of Config.
23 24 25 |
# File 'lib/collie/config.rb', line 23 def initialize(config_path = nil) @config = load_config(config_path) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
21 22 23 |
# File 'lib/collie/config.rb', line 21 def config @config end |
Class Method Details
.default ⇒ Object
50 51 52 |
# File 'lib/collie/config.rb', line 50 def self.default new end |
.generate_default(path = ".collie.yml") ⇒ Object
54 55 56 |
# File 'lib/collie/config.rb', line 54 def self.generate_default(path = ".collie.yml") File.write(path, DEFAULT_CONFIG.to_yaml) end |
Instance Method Details
#excluded_patterns ⇒ Object
46 47 48 |
# File 'lib/collie/config.rb', line 46 def excluded_patterns @config["exclude"] || DEFAULT_CONFIG["exclude"] end |
#formatter_options ⇒ Object
38 39 40 |
# File 'lib/collie/config.rb', line 38 def @config["formatter"] || DEFAULT_CONFIG["formatter"] end |
#included_patterns ⇒ Object
42 43 44 |
# File 'lib/collie/config.rb', line 42 def included_patterns @config["include"] || DEFAULT_CONFIG["include"] end |
#rule_config(rule_name) ⇒ Object
34 35 36 |
# File 'lib/collie/config.rb', line 34 def rule_config(rule_name) @config.dig("rules", rule_name) || {} end |
#rule_enabled?(rule_name) ⇒ Boolean
27 28 29 30 31 32 |
# File 'lib/collie/config.rb', line 27 def rule_enabled?(rule_name) rule_config = @config.dig("rules", rule_name) return true if rule_config.nil? # Enabled by default rule_config.is_a?(Hash) ? rule_config.fetch("enabled", true) : rule_config end |