class Cuprum::Rails::Commands::UpdateOne

Command for updating an ActiveRecord record in the collection.

Private Instance Methods

handle_missing_record(primary_key:) click to toggle source
# File lib/cuprum/rails/commands/update_one.rb, line 26
def handle_missing_record(primary_key:)
  query = record_class.where(primary_key_name => primary_key)

  return if query.exists?

  error = Cuprum::Collections::Errors::NotFound.new(
    collection_name:    collection_name,
    primary_key_name:   primary_key_name,
    primary_key_values: primary_key
  )
  failure(error)
end
process(entity:) click to toggle source
# File lib/cuprum/rails/commands/update_one.rb, line 39
def process(entity:)
  step { validate_entity(entity) }

  step { handle_missing_record(primary_key: entity[primary_key_name]) }

  entity.save

  entity
end