Class: Textus::Maintenance::KeyDeletePrefix
- Inherits:
-
Object
- Object
- Textus::Maintenance::KeyDeletePrefix
- Defined in:
- lib/textus/maintenance/key_delete_prefix.rb
Overview
Bulk-delete every leaf key under ‘prefix`.
Instance Method Summary collapse
- #call(prefix:, dry_run: false) ⇒ Object
-
#initialize(container:, call:) ⇒ KeyDeletePrefix
constructor
A new instance of KeyDeletePrefix.
Constructor Details
#initialize(container:, call:) ⇒ KeyDeletePrefix
Returns a new instance of KeyDeletePrefix.
5 6 7 8 |
# File 'lib/textus/maintenance/key_delete_prefix.rb', line 5 def initialize(container:, call:) @container = container @call = call end |
Instance Method Details
#call(prefix:, dry_run: false) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/textus/maintenance/key_delete_prefix.rb', line 10 def call(prefix:, dry_run: false) raise UsageError.new("prefix required") if prefix.nil? || prefix.empty? leaves = Read::List.new(container: @container) .call(prefix: prefix) .map { |r| r.is_a?(Hash) ? (r["key"] || r[:key]) : r } warnings = leaves.empty? ? ["no keys under #{prefix}"] : [] steps = leaves.map { |k| { "op" => "delete", "key" => k } } plan = Plan.new(steps: steps, warnings: warnings) return plan if dry_run steps.each do |s| delete.call(s["key"]) end plan end |