Class: HamlLint::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options, file = nil) ⇒ Configuration

Creates a configuration from the given options hash.

Parameters:

  • options (Hash)


17
18
19
20
21
22
# File 'lib/haml_lint/configuration.rb', line 17

def initialize(options, file = nil)
  @hash = options
  @config_dir = file ? File.dirname(file) : nil
  resolve_requires
  validate
end

Instance Attribute Details

#hashObject (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.

Parameters:

Returns:

  • (true, false)

    whether the given configuration is equivalent



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.

Parameters:

  • key (String)

Returns:

  • (Array, Hash, Number, String)


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.

Parameters:



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.

Parameters:



60
61
62
# File 'lib/haml_lint/configuration.rb', line 60

def merge(config)
  self.class.new(smart_merge(@hash, config.hash))
end