Class: YamlSmith::DeleteKey

Inherits:
FileCommand show all
Defined in:
lib/yaml_smith/delete_key.rb

Overview

Deletes a top-level key from a YAML file.

Instance Method Summary collapse

Methods inherited from FileCommand

call, #initialize

Constructor Details

This class inherits a constructor from YamlSmith::FileCommand

Instance Method Details

#callObject

Raises:



6
7
8
9
10
11
12
13
14
# File 'lib/yaml_smith/delete_key.rb', line 6

def call
  document = load_file(@path)

  ensure_mapping(document)
  raise Error, "key does not exist: #{@key}" unless document.key?(@key)

  document.delete(@key)
  write(Psych::Pure.dump(document))
end