Class: YamlSmith::DeleteKey
- Inherits:
-
FileCommand
- Object
- FileCommand
- YamlSmith::DeleteKey
- Defined in:
- lib/yaml_smith/delete_key.rb
Overview
Deletes matching keys from a YAML file.
Instance Method Summary collapse
Methods inherited from FileCommand
Constructor Details
This class inherits a constructor from YamlSmith::FileCommand
Instance Method Details
#call(top_level_only: false) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/yaml_smith/delete_key.rb', line 6 def call(top_level_only: false) document = load_file(@path) ensure_mapping(document) deleted = top_level_only ? !document.delete(@key).nil? : delete_key(document) raise Error, "key does not exist: #{@key}" unless deleted write(Psych::Pure.dump(document)) end |