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

TODO:

Add custom doc



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

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



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

def call(attributes)
  values = yield validate_contract(attributes)
  values = yield assign_default_values(values)

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

  Success(@auction)
end