Class: Textus::Maintenance::KeyDeletePrefix
- Inherits:
-
Object
- Object
- Textus::Maintenance::KeyDeletePrefix
- Extended by:
- Contract::DSL
- 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.
Methods included from Contract::DSL
arg, contract, contract?, response, summary, surfaces, verb
Constructor Details
#initialize(container:, call:) ⇒ KeyDeletePrefix
Returns a new instance of KeyDeletePrefix.
14 15 16 17 |
# File 'lib/textus/maintenance/key_delete_prefix.rb', line 14 def initialize(container:, call:) @container = container @call = call end |
Instance Method Details
#call(prefix:, dry_run: false) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/textus/maintenance/key_delete_prefix.rb', line 19 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 |