Module: RailVerdict::Init

Defined in:
lib/rail_verdict/init.rb

Constant Summary collapse

CONFIGURATION =
<<~YAML
  version: 1
  mode: no_new_debt
  analyzers:
    rubocop:
      enabled: true
      required: true
YAML

Class Method Summary collapse

Class Method Details

.write(root:, config_path:, force: false) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rail_verdict/init.rb', line 18

def write(root:, config_path:, force: false)
  path = Pathname.new(config_path.to_s)
  path = Pathname.new(File.expand_path(path.to_s, root)) unless path.absolute?
  if path.exist? && !force
    return [2, "configuration already exists: #{relative_path(path.to_s, root)}; use --force to overwrite"]
  end
  parent = path.dirname
  return [2, "configuration directory does not exist: #{relative_path(parent.to_s, root)}"] unless parent.directory?

  File.write(path, CONFIGURATION)
  [0, "initialized #{relative_path(path.to_s, root)}"]
rescue SystemCallError => error
  [2, "could not write configuration: #{error.message}"]
end