Class: SlimLint::Configuration
- Inherits:
-
Object
- Object
- SlimLint::Configuration
- Defined in:
- lib/slim_lint/configuration.rb
Overview
Stores runtime configuration for the application.
The purpose of this class is to validate and ensure all configurations satisfy some basic pre-conditions so other parts of the application don’t have to check the configuration for errors. It should have no knowledge of how these configuration values are ultimately used.
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Internal hash storing the configuration.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Compares this configuration with another.
-
#[](key) ⇒ Array, ...
Access the configuration as if it were a hash.
-
#for_linter(linter) ⇒ Object
Returns a non-modifiable configuration for the specified linter.
-
#initialize(options) ⇒ Configuration
constructor
Creates a configuration from the given options hash.
-
#merge(config) ⇒ Object
Merges the given configuration with this one, returning a new Configuration.
Constructor Details
#initialize(options) ⇒ Configuration
Creates a configuration from the given options hash.
17 18 19 20 |
# File 'lib/slim_lint/configuration.rb', line 17 def initialize() @hash = validate end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Internal hash storing the configuration.
12 13 14 |
# File 'lib/slim_lint/configuration.rb', line 12 def hash @hash end |
Instance Method Details
#==(other) ⇒ true, false
Compares this configuration with another.
34 35 36 |
# File 'lib/slim_lint/configuration.rb', line 34 def ==(other) super || @hash == other.hash end |
#[](key) ⇒ Array, ...
Access the configuration as if it were a hash.
26 27 28 |
# File 'lib/slim_lint/configuration.rb', line 26 def [](key) @hash[key] end |
#for_linter(linter) ⇒ Object
Returns a non-modifiable configuration for the specified linter.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/slim_lint/configuration.rb', line 41 def for_linter(linter) linter_name = case linter when Class linter.name.split('::').last when SlimLint::Linter linter.name end @hash['linters'].fetch(linter_name, {}).dup.freeze end |
#merge(config) ⇒ Object
Merges the given configuration with this one, returning a new SlimLint::Configuration. The provided configuration will either add to or replace any options defined in this configuration.
58 59 60 |
# File 'lib/slim_lint/configuration.rb', line 58 def merge(config) self.class.new(smart_merge(@hash, config.hash)) end |