class RubocopChallenger::Rubocop::ConfigEditor
To edit rubocop_challenger config file
Constants
- DEFAULT_FILE_PATH
Attributes
data[R]
file_path[R]
Public Class Methods
new(file_path: DEFAULT_FILE_PATH)
click to toggle source
# File lib/rubocop_challenger/rubocop/config_editor.rb, line 13 def initialize(file_path: DEFAULT_FILE_PATH) @file_path = file_path @data = FileTest.exist?(file_path) ? YAML.load_file(file_path) : {} end
Public Instance Methods
add_ignore(*rules)
click to toggle source
Add ignore rule to the config data
@param rules [Array<Rubocop::Rule>] The target rules
# File lib/rubocop_challenger/rubocop/config_editor.rb, line 28 def add_ignore(*rules) data['Ignore'] ||= [] rules.each { |rule| data['Ignore'] << rule.title } data['Ignore'].sort!.uniq! end
ignored_rules()
click to toggle source
Get ignored rules
@return [Array<String>] Ignored rules
# File lib/rubocop_challenger/rubocop/config_editor.rb, line 21 def ignored_rules data['Ignore'] || [] end
save()
click to toggle source
Save setting to the config file as YAML
# File lib/rubocop_challenger/rubocop/config_editor.rb, line 35 def save File.open(file_path, 'w') do |file| YAML.dump(data, file) end end