Next-gen ruby libs! » github.com/dry-rb » website: https://dry-rb.org » forum: https://discourse.dry-rb.org
Dry::Transcation::Operation
when it returns a block?Operation.new.call(arg) do |result|
result.success { ... }
result.failure { ... }
end
Is it still possible to inject a operation, even if i’m using inside other operation:
i.e:
class CheckAccess
include Dry::Transaction::Operation
def call(user)
return Success(user.licenses.first) if active_license_for?(user)
check_purchase = CheckPurchase.new
check_purchase.call(user.purchases.first) do |result|
result.success do |purchase|
Success(purchase)
end
result.failure do
if user.on_trial?
Success(Trial.new(user: user))
else
Failure(user)
end
end
end
end
private
def active_license_for?(user)
user.licenses.first_or_initialize.active?
end
end
check_purchase.call(user.purchases.first).or {
if user.on_trial?
Success(Trial.new(user: user))
else
Failure(user)
end
}
check_purchase
operation cannot injected given you hard code its initialization in the call method
def initialize(check_purchase:)
@check_purchase = check_purchase
end
#call
and also inject a test double during your tests
include Dry::Transaction(container: Container)
for Operations right? Is that a flaw on my desing? should operations not depend on other operations as a common practice?