Class: HamlLint::Configuration
- Inherits:
-
Object
- Object
- HamlLint::Configuration
- Defined in:
- lib/haml_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.
15 16 17 18 |
# File 'lib/haml_lint/configuration.rb', line 15 def initialize() @hash = validate end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Internal hash storing the configuration.
10 11 12 |
# File 'lib/haml_lint/configuration.rb', line 10 def hash @hash end |
Instance Method Details
#==(other) ⇒ true, false
Compares this configuration with another.
32 33 34 |
# File 'lib/haml_lint/configuration.rb', line 32 def ==(other) super || @hash == other.hash end |
#[](key) ⇒ Array, ...
Access the configuration as if it were a hash.
24 25 26 |
# File 'lib/haml_lint/configuration.rb', line 24 def [](key) @hash[key] end |
#for_linter(linter) ⇒ Object
Returns a non-modifiable configuration for the specified linter.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/haml_lint/configuration.rb', line 39 def for_linter(linter) linter_name = case linter when Class linter.name.split('::').last when HamlLint::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 HamlLint::Configuration. The provided configuration will either add to or replace any options defined in this configuration.
56 57 58 |
# File 'lib/haml_lint/configuration.rb', line 56 def merge(config) self.class.new(smart_merge(@hash, config.hash)) end |