Class: AuctionFunCore::Operations::AuctionContext::CreateOperation

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

Overview

Operation class for creating auctions.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(attributes, &block) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/auction_fun_core/operations/auction_context/create_operation.rb', line 15

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) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/auction_fun_core/operations/auction_context/create_operation.rb', line 23

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

  auction_repository.transaction do |_t|
    @auction = yield persist(values)
    yield scheduled_start_auction(@auction)
    yield publish_auctions_created(@auction)
  end

  Success(@auction)
end