timriley on remove-auto-register
We don’t need to pass loader th… We don’t take arbitrary options… Container.component can be priv… (compare)
timriley on remove-auto-register
Expand tests Flesh out specs (compare)
timriley on remove-auto-register
Remove commented code (compare)
timriley on remove-auto-register
Remove no-longer-relevant doc (compare)
timriley on remove-auto-register
Remove another unneeded splat (compare)
timriley on remove-auto-register
Li’l tweak (compare)
timriley on remove-auto-register
Li’l tweak (compare)
timriley on remove-auto-register
Simplify args passed to build_f… (compare)
timriley on remove-auto-register
Further simplify args for build… (compare)
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
}
def initialize(check_purchase:)
@check_purchase = check_purchase
end
#call
and also inject a test double during your tests
# frozen_string_literal: true
require "dry/transaction/operation"
class CheckAccess
include Dry::Transaction::Operation
def initialize(check_purchase: CheckPurchase.new)
@check_purchase = check_purchase
end
def call(user)
return Success(user.licenses.first) if active_license_for?(user)
@check_purchase.call(user.purchases.first).or(
if user.on_trial?
Success(Trial.new(user: user))
else
Failure(user)
end
)
end
private
def active_license_for?(user)
user.licenses.first_or_initialize.active?
end
end
irb(main):003:0> Try { Failure(5) }.to_result.bind(&:itself)
=> Failure(5)
irb(main):004:0> Try { raise RuntimeError.new }.to_result.bind(&:itself)
=> Failure(#<RuntimeError: RuntimeError>)
irb(main):005:0> Try { Success(1) }.to_result.bind(&:itself)
=> Success(1)