Class: AuctionFunCore::Operations::AuctionContext::Processor::PauseOperation

Inherits:
Base
  • Object
show all
Defined in:
lib/auction_fun_core/operations/auction_context/processor/pause_operation.rb

Overview

Operation class for dispatch pause auction. By default, this change auction status from ‘running’ to ‘paused’.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(attributes) {|Dry::Matcher::Evaluator| ... } ⇒ Dry::Matcher::Evaluator

Executes the pause operation with the provided attributes.

Examples:

attributes = { auction_id: 123 }

AuctionFunCore::Operations::AuctionContext::Processor::PauseOperation.call(attributes) do |result|
  result.success { |auction| puts "Paused auction sucessfully! #{auction.to_h}" }
  result.failure { |failure| puts "Failed to pause auction: #{failure.errors.to_h}"}
end

Parameters:

  • attributes (Hash)

    The attributes for the pause operation.

Options Hash (attributes):

  • auction_id (Integer)

    The ID of the auction.

Yields:

  • (Dry::Matcher::Evaluator)

    The block to handle the result of the operation.

Returns:

  • (Dry::Matcher::Evaluator)

    The result of the operation.



30
31
32
33
34
35
36
# File 'lib/auction_fun_core/operations/auction_context/processor/pause_operation.rb', line 30

def self.call(attributes, &block)
  operation = new.call(attributes)

  return operation unless block

  Dry::Matcher::ResultMatcher.call(operation, &block)
end

Instance Method Details

#call(attributes) ⇒ Dry::Monads::Result::Success, Dry::Monads::Result::Failure

Performing an auction pause

Examples:

attributes = { auction_id: 123 }

operation = AuctionFunCore::Operations::AuctionContext::Processor::PauseOperation.call(attributes)

if operation.success?
  auction = operation.success
  puts "Paused auction sucessfully! #{auction.to_h}"
end

if operation.failure?
  failure = operation.failure
  puts "Failed to pause auction: #{failure.errors.to_h}"
end

Parameters:

  • attributes (Hash)

    The attributes for the pause operation.

Options Hash (attributes):

  • auction_id (Integer)

    The ID of the auction.

Returns:

  • (Dry::Monads::Result::Success, Dry::Monads::Result::Failure)

    The result of the operation.



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/auction_fun_core/operations/auction_context/processor/pause_operation.rb', line 59

def call(attributes)
  attrs = yield validate(attributes)

  auction_repository.transaction do |_t|
    @auction, _ = auction_repository.update(attrs[:auction_id], status: "paused")

    publish_auction_pause_event(@auction)
  end

  Success(attrs[:auction_id])
end