class Ruboclean::RubocopConfigurationPath
Interface for reading and writing the `.rubocop.yml` file
Public Class Methods
new(path)
click to toggle source
# File lib/ruboclean/rubocop_configuration_path.rb, line 16 def initialize(path) input_path = Pathname.new(path) @rubocop_configuration_path = if input_path.directory? input_path.join('.rubocop.yml') else input_path end raise InvalidPathError, @rubocop_configuration_path unless @rubocop_configuration_path.exist? end
Public Instance Methods
load()
click to toggle source
# File lib/ruboclean/rubocop_configuration_path.rb, line 28 def load Ruboclean::RubocopConfiguration.new(load_yaml) end
write(rubocop_configuration)
click to toggle source
# File lib/ruboclean/rubocop_configuration_path.rb, line 32 def write(rubocop_configuration) output = sanitize_yaml(rubocop_configuration.to_yaml) @rubocop_configuration_path.write(output) end
Private Instance Methods
load_yaml()
click to toggle source
# File lib/ruboclean/rubocop_configuration_path.rb, line 43 def load_yaml YAML.safe_load(@rubocop_configuration_path.read) end
sanitize_yaml(data)
click to toggle source
# File lib/ruboclean/rubocop_configuration_path.rb, line 39 def sanitize_yaml(data) data.gsub(/^([a-zA-Z]+)/, "\n\\1") end