Class: Textus::Application::Maintenance::KeyDeletePrefix::Impl
- Inherits:
-
Object
- Object
- Textus::Application::Maintenance::KeyDeletePrefix::Impl
- Defined in:
- lib/textus/application/maintenance/key_delete_prefix.rb
Instance Method Summary collapse
- #call(prefix:, dry_run: false) ⇒ Object
-
#initialize(ctx:, caps:, session:) ⇒ Impl
constructor
A new instance of Impl.
Constructor Details
#initialize(ctx:, caps:, session:) ⇒ Impl
Returns a new instance of Impl.
11 12 13 14 15 |
# File 'lib/textus/application/maintenance/key_delete_prefix.rb', line 11 def initialize(ctx:, caps:, session:) @ctx = ctx @caps = caps @session = session end |
Instance Method Details
#call(prefix:, dry_run: false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/textus/application/maintenance/key_delete_prefix.rb', line 17 def call(prefix:, dry_run: false) raise UsageError.new("prefix required") if prefix.nil? || prefix.empty? leaves = Read::List::Impl.new(caps: @caps) .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| Textus::Application::Write::Delete.call( s["key"], session: @session, ctx: @ctx, caps: @session.write_caps, ) end plan end |