Class: ERBLint::LinterConfig
- Inherits:
-
Object
- Object
- ERBLint::LinterConfig
show all
- Includes:
- SmartProperties
- Defined in:
- lib/erb_lint/linter_config.rb
Direct Known Subclasses
ERBLint::Linters::AllowedScriptType::ConfigSchema, ERBLint::Linters::DeprecatedClasses::ConfigSchema, ERBLint::Linters::ErbSafety::ConfigSchema, ERBLint::Linters::FinalNewline::ConfigSchema, ERBLint::Linters::HardCodedString::ConfigSchema, ERBLint::Linters::NoJavascriptTagHelper::ConfigSchema, ERBLint::Linters::RightTrim::ConfigSchema, ERBLint::Linters::Rubocop::ConfigSchema, ERBLint::Linters::RubocopText::ConfigSchema, ERBLint::Linters::SelfClosingTag::ConfigSchema, ERBLint::Linters::SpaceIndentation::ConfigSchema
Defined Under Namespace
Classes: Error
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config = {}) ⇒ LinterConfig
Returns a new instance of LinterConfig.
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/erb_lint/linter_config.rb', line 25
def initialize(config = {})
config = config.dup.deep_stringify_keys
allowed_keys = self.class.properties.keys.map(&:to_s)
given_keys = config.keys
if ( = given_keys - allowed_keys).any?
raise Error, "Given key is not allowed: #{.join(", ")}"
end
super(config)
rescue SmartProperties::InitializationError => e
raise Error, "The following properties are required to be set: #{e.properties}"
rescue SmartProperties::InvalidValueError => e
raise Error, e.message
end
|
Class Method Details
.array_of?(klass) ⇒ Boolean
13
14
15
|
# File 'lib/erb_lint/linter_config.rb', line 13
def array_of?(klass)
lambda { |value| value.is_a?(Array) && value.all? { |s| s.is_a?(klass) } }
end
|
.to_array_of(klass) ⇒ Object
17
18
19
|
# File 'lib/erb_lint/linter_config.rb', line 17
def to_array_of(klass)
lambda { |entries| entries.map { |entry| klass.new(entry) } }
end
|
Instance Method Details
#[](name) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/erb_lint/linter_config.rb', line 40
def [](name)
unless self.class.properties.key?(name)
raise Error, "No such property: #{name}"
end
super
end
|
#excludes_file?(absolute_filename, base_path) ⇒ Boolean
56
57
58
59
60
61
62
63
|
# File 'lib/erb_lint/linter_config.rb', line 56
def excludes_file?(absolute_filename, base_path)
exclude.any? do |path|
return true if File.fnmatch?(path, absolute_filename)
relative_path = absolute_filename.delete_prefix("#{base_path}/")
File.fnmatch?(path, relative_path)
end
end
|
#to_hash ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/erb_lint/linter_config.rb', line 48
def to_hash
{}.tap do |hash|
self.class.properties.to_hash.each_key do |key|
hash[key.to_s] = self[key]
end
end
end
|