Class: HamlLint::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/haml_lint/configuration.rb

Overview

Stores configuration for haml-lint.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Configuration

Creates a configuration from the given options hash.

Parameters:

  • options (Hash)

9
10
11
12
# File 'lib/haml_lint/configuration.rb', line 9

def initialize(options)
  @hash = options
  validate
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash


4
5
6
# File 'lib/haml_lint/configuration.rb', line 4

def hash
  @hash
end

Instance Method Details

#==(other) ⇒ true, false Also known as: eql?

Compares this configuration with another.

Parameters:

Returns:

  • (true, false)

    whether the given configuration is equivalent


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

def ==(other)
  super || @hash == other.hash
end

#for_linter(linter) ⇒ Object

Returns a non-modifiable configuration for the specified linter.

Parameters:


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/haml_lint/configuration.rb', line 26

def for_linter(linter)
  linter_name =
    case linter
    when Class
      linter.name.split('::').last
    when HamlLint::Linter
      linter.name
    else
      linter.to_s
    end

  smart_merge(@hash['linters']['ALL'],
              @hash['linters'].fetch(linter_name, {})).freeze
end

#linter_enabled?(linter) ⇒ Boolean

Returns whether the specified linter is enabled by this configuration.

Parameters:

Returns:

  • (Boolean)

44
45
46
# File 'lib/haml_lint/configuration.rb', line 44

def linter_enabled?(linter)
  for_linter(linter)['enabled'] != false
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:


53
54
55
# File 'lib/haml_lint/configuration.rb', line 53

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