Class: AuctionFunCore::Operations::AuctionContext::Processor::UnpauseOperation

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

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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

Executes the unpause operation with the provided attributes.

Examples:

attributes = { auction_id: 123 }

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

Parameters:

  • attributes (Hash)

    The attributes for the unpause 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/unpause_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

Performs the unpause of an auction.

Examples:

attributes = { auction_id: 123 }

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

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

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

Parameters:

  • attributes (Hash)

    The attributes for the unpause 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/unpause_operation.rb', line 59

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

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

    publish_auction_unpause_event(@auction)
  end

  Success(attrs[:auction_id])
end