class Cuprum::Collections::Basic::Commands::DestroyOne

Command for destroying one collection item by primary key.

Private Instance Methods

handle_missing_item(index:, primary_key:) click to toggle source
# File lib/cuprum/collections/basic/commands/destroy_one.rb, line 27
def handle_missing_item(index:, primary_key:)
  return if index

  error = Cuprum::Collections::Errors::NotFound.new(
    collection_name:    collection_name,
    primary_key_name:   primary_key_name,
    primary_key_values: [primary_key]
  )
  Cuprum::Result.new(error: error)
end
process(primary_key:) click to toggle source
# File lib/cuprum/collections/basic/commands/destroy_one.rb, line 38
def process(primary_key:)
  step { validate_primary_key(primary_key) }

  index = data.index { |item| item[primary_key_name.to_s] == primary_key }

  step { handle_missing_item(index: index, primary_key: primary_key) }

  data.delete_at(index)
end