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, file = nil) ⇒ 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, file = nil) ⇒ Configuration
Creates a configuration from the given options hash.
17 18 19 20 21 22 |
# File 'lib/haml_lint/configuration.rb', line 17 def initialize(, file = nil) @hash = @config_dir = file ? File.dirname(file) : nil resolve_requires validate end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Internal hash storing the configuration.
12 13 14 |
# File 'lib/haml_lint/configuration.rb', line 12 def hash @hash end |
Instance Method Details
#==(other) ⇒ true, false
Compares this configuration with another.
36 37 38 |
# File 'lib/haml_lint/configuration.rb', line 36 def ==(other) super || @hash == other.hash end |
#[](key) ⇒ Array, ...
Access the configuration as if it were a hash.
28 29 30 |
# File 'lib/haml_lint/configuration.rb', line 28 def [](key) @hash[key] end |
#for_linter(linter) ⇒ Object
Returns a non-modifiable configuration for the specified linter.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/haml_lint/configuration.rb', line 43 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.
60 61 62 |
# File 'lib/haml_lint/configuration.rb', line 60 def merge(config) self.class.new(smart_merge(@hash, config.hash)) end |