Class: Dry::Transaction::Extra::PerformLater::ConfiguredJob

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/transaction/extra/perform_later.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_class, transaction, options = {}) ⇒ ConfiguredJob

Returns a new instance of ConfiguredJob.



33
34
35
36
37
# File 'lib/dry/transaction/extra/perform_later.rb', line 33

def initialize(job_class, transaction, options = {})
  @job_class = job_class
  @transaction = transaction
  @options = options
end

Instance Attribute Details

#job_classObject (readonly)

Returns the value of attribute job_class.



31
32
33
# File 'lib/dry/transaction/extra/perform_later.rb', line 31

def job_class
  @job_class
end

#optionsObject (readonly)

Returns the value of attribute options.



31
32
33
# File 'lib/dry/transaction/extra/perform_later.rb', line 31

def options
  @options
end

#transactionObject (readonly)

Returns the value of attribute transaction.



31
32
33
# File 'lib/dry/transaction/extra/perform_later.rb', line 31

def transaction
  @transaction
end

Instance Method Details

#perform_later(*args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dry/transaction/extra/perform_later.rb', line 39

def perform_later(*args)
  args.last.reverse_merge!(@options[:perform_with]) if @options[:perform_with]

  if validator
    result = validator.new.call(*args).to_monad
    return result unless result.success?

    args = [result.value!.to_h]
  end

  Dry::Monads::Success(
    job_class.new(transaction_class_name: @transaction.name, args:)
      .enqueue(@options)
  )
end

#validatorObject



55
56
57
# File 'lib/dry/transaction/extra/perform_later.rb', line 55

def validator
  @transaction.validator
end