Class: LintTrappings::Configuration
- Inherits:
-
Object
- Object
- LintTrappings::Configuration
- Defined in:
- lib/lint_trappings/configuration.rb
Overview
Stores runtime configuration for the application.
Instance Attribute Summary collapse
-
#path ⇒ String
The path of this configuration, if it was loaded from a file.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Compares this configuration with another.
- #[](key) ⇒ Object
- #delete(key) ⇒ Object
- #fetch(*args, &block) ⇒ Object
- #for_linter(linterish) ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
Creates a configuration from the given options hash.
-
#merge(config) ⇒ LintTrappings::Configuration
Merges the given configuration with this one.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Creates a configuration from the given options hash.
18 19 20 |
# File 'lib/lint_trappings/configuration.rb', line 18 def initialize( = {}) @hash = .dup end |
Instance Attribute Details
#path ⇒ String
The path of this configuration, if it was loaded from a file.
Used in certain scenarios to determine the absolute path of a file specified in a configuration (i.e. getting the path relative to the location of the configuration file itself).
13 14 15 |
# File 'lib/lint_trappings/configuration.rb', line 13 def path @path end |
Instance Method Details
#==(other) ⇒ true, false
Compares this configuration with another.
27 28 29 |
# File 'lib/lint_trappings/configuration.rb', line 27 def ==(other) super || @hash == other.hash end |
#[](key) ⇒ Object
35 36 37 |
# File 'lib/lint_trappings/configuration.rb', line 35 def [](key) @hash[key] end |
#delete(key) ⇒ Object
39 40 41 |
# File 'lib/lint_trappings/configuration.rb', line 39 def delete(key) @hash.delete(key) end |
#fetch(*args, &block) ⇒ Object
31 32 33 |
# File 'lib/lint_trappings/configuration.rb', line 31 def fetch(*args, &block) @hash.fetch(*args, &block) end |
#for_linter(linterish) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/lint_trappings/configuration.rb', line 56 def for_linter(linterish) linter_name = case linterish when Class, LintTrappings::Linter linterish.canonical_name else linterish.to_s end conf = @hash.fetch('linters', {}).fetch(linter_name, {}).dup conf['severity'] ||= @hash.fetch('default_severity', :error) conf['severity'] = conf['severity'].to_sym conf end |
#merge(config) ⇒ LintTrappings::Configuration
Merges the given configuration with this one.
The provided configuration will either add to or replace any options defined in this configuration.
51 52 53 54 |
# File 'lib/lint_trappings/configuration.rb', line 51 def merge(config) merged_hash = smart_merge(@hash, config.hash) self.class.new(merged_hash) end |