Class: AuctionFunCore::Operations::AuctionContext::Processor::StartOperation

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

Overview

Operation class for dispatch start auction. By default, this change auction status from ‘scheduled’ to ‘running’ and schedule a job to execute the auction finalization when auction is not penny.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(attributes, &block) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/auction_fun_core/operations/auction_context/processor/start_operation.rb', line 19

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) ⇒ ROM::Struct::Auction

Returns auction object.

Parameters:

  • attributes (Hash)

    needed to start a auction

  • opts (Hash)

    a customizable set of options

Returns:

  • (ROM::Struct::Auction)

    auction object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/auction_fun_core/operations/auction_context/processor/start_operation.rb', line 32

def call(attributes)
  auction, attrs = yield validate_contract(attributes)

  auction_repository.transaction do |_t|
    @auction, _ = auction_repository.update(auction.id, update_params(auction, attrs))

    yield publish_auction_start_event(@auction)
    yield scheduled_finished_auction(@auction)
  end

  Success(@auction)
end