Class: Yamlint::Config
- Inherits:
-
Object
- Object
- Yamlint::Config
- Defined in:
- lib/yamlint/config.rb
Constant Summary collapse
- DEFAULT_CONFIG_FILES =
%w[ .yamllint .yamllint.yaml .yamllint.yml ].freeze
- YAML_FILE_PATTERNS =
%w[ *.yaml *.yml ].freeze
Instance Attribute Summary collapse
-
#extends ⇒ Object
readonly
Returns the value of attribute extends.
-
#ignore ⇒ Object
readonly
Returns the value of attribute ignore.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#yaml_files ⇒ Object
readonly
Returns the value of attribute yaml_files.
Class Method Summary collapse
- .build_from_hash(data) ⇒ Object
- .find_config_file ⇒ Object
- .load(path = nil) ⇒ Object
- .load_default ⇒ Object
- .load_from_file(path) ⇒ Object
- .new_with_preset(preset_name) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #rule_config(rule_id) ⇒ Object
- #rule_enabled?(rule_id) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
20 21 22 23 24 25 |
# File 'lib/yamlint/config.rb', line 20 def initialize( = {}) @extends = [:extends] @yaml_files = [:'yaml-files'] || ['yaml-files'] || YAML_FILE_PATTERNS @ignore = [:ignore] || ['ignore'] || [] @rules = normalize_rules([:rules] || ['rules'] || {}) end |
Instance Attribute Details
#extends ⇒ Object (readonly)
Returns the value of attribute extends.
18 19 20 |
# File 'lib/yamlint/config.rb', line 18 def extends @extends end |
#ignore ⇒ Object (readonly)
Returns the value of attribute ignore.
18 19 20 |
# File 'lib/yamlint/config.rb', line 18 def ignore @ignore end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
18 19 20 |
# File 'lib/yamlint/config.rb', line 18 def rules @rules end |
#yaml_files ⇒ Object (readonly)
Returns the value of attribute yaml_files.
18 19 20 |
# File 'lib/yamlint/config.rb', line 18 def yaml_files @yaml_files end |
Class Method Details
.build_from_hash(data) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/yamlint/config.rb', line 59 def self.build_from_hash(data) base_config = if data['extends'] Presets.get(data['extends']) else {} end merged = deep_merge(base_config, symbolize_keys(data)) new(merged) end |
.find_config_file ⇒ Object
50 51 52 |
# File 'lib/yamlint/config.rb', line 50 def self.find_config_file DEFAULT_CONFIG_FILES.find { |f| File.exist?(f) } end |
.load(path = nil) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/yamlint/config.rb', line 27 def self.load(path = nil) if path load_from_file(path) else load_default end end |
.load_default ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/yamlint/config.rb', line 41 def self.load_default config_file = find_config_file if config_file load_from_file(config_file) else new_with_preset('default') end end |
.load_from_file(path) ⇒ Object
35 36 37 38 39 |
# File 'lib/yamlint/config.rb', line 35 def self.load_from_file(path) content = File.read(path) data = YAML.safe_load(content, permitted_classes: [Symbol]) || {} build_from_hash(data) end |
Instance Method Details
#rule_config(rule_id) ⇒ Object
70 71 72 |
# File 'lib/yamlint/config.rb', line 70 def rule_config(rule_id) @rules[rule_id.to_s] || @rules[rule_id.to_sym] || {} end |
#rule_enabled?(rule_id) ⇒ Boolean
74 75 76 77 |
# File 'lib/yamlint/config.rb', line 74 def rule_enabled?(rule_id) config = rule_config(rule_id) config != 'disable' && config != false end |