Class: RubocopChallenger::Rubocop::ConfigEditor
- Inherits:
-
Object
- Object
- RubocopChallenger::Rubocop::ConfigEditor
- Defined in:
- lib/rubocop_challenger/rubocop/config_editor.rb
Overview
To edit rubocop_challenger config file
Constant Summary collapse
- DEFAULT_FILE_PATH =
'.rubocop_challenge.yml'
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Instance Method Summary collapse
-
#add_ignore(*rules) ⇒ Object
Add ignore rule to the config data.
-
#ignored_rules ⇒ Array<String>
Get ignored rules.
-
#initialize(file_path: DEFAULT_FILE_PATH) ⇒ ConfigEditor
constructor
A new instance of ConfigEditor.
-
#save ⇒ Object
Save setting to the config file as YAML.
Constructor Details
#initialize(file_path: DEFAULT_FILE_PATH) ⇒ ConfigEditor
Returns a new instance of ConfigEditor.
13 14 15 16 |
# 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 |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
11 12 13 |
# File 'lib/rubocop_challenger/rubocop/config_editor.rb', line 11 def data @data end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
11 12 13 |
# File 'lib/rubocop_challenger/rubocop/config_editor.rb', line 11 def file_path @file_path end |
Instance Method Details
#add_ignore(*rules) ⇒ Object
Add ignore rule to the config data
28 29 30 31 32 |
# 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 ⇒ Array<String>
Get ignored rules
21 22 23 |
# File 'lib/rubocop_challenger/rubocop/config_editor.rb', line 21 def ignored_rules data['Ignore'] || [] end |
#save ⇒ Object
Save setting to the config file as YAML
35 36 37 38 39 |
# 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 |