Class: Textus::Handlers::Write::KeyDeletePrefix
- Inherits:
-
Object
- Object
- Textus::Handlers::Write::KeyDeletePrefix
- Defined in:
- lib/textus/handlers/write/key_delete_prefix.rb
Instance Method Summary collapse
- #call(command, call) ⇒ Object
-
#initialize(orchestration:) ⇒ KeyDeletePrefix
constructor
A new instance of KeyDeletePrefix.
Constructor Details
#initialize(orchestration:) ⇒ KeyDeletePrefix
Returns a new instance of KeyDeletePrefix.
5 6 7 |
# File 'lib/textus/handlers/write/key_delete_prefix.rb', line 5 def initialize(orchestration:) @orchestration = orchestration end |
Instance Method Details
#call(command, call) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/textus/handlers/write/key_delete_prefix.rb', line 9 def call(command, call) return Value::Result.failure(:usage_error, "prefix required") if command.prefix.nil? || command.prefix.empty? list = @orchestration.list_keys(prefix: command.prefix, lane: nil, call: call) return list if list.failure? leaves = list.value.fetch("rows") warnings = leaves.empty? ? ["no keys under #{command.prefix}"] : [] steps = leaves.map { |row| { "op" => "delete", "key" => row["key"] } } plan = Textus::Store::Jobs::Plan.new(steps: steps, warnings: warnings) return Value::Result.success(plan) if command.dry_run steps.each do |step| delete = @orchestration.delete_key(key: step["key"], call: call) return delete if delete.failure? end Value::Result.success(plan) end |