examples/business_processes/app/models/account/owner_creation.rb in bcdd-process-0.2.0 vs examples/business_processes/app/models/account/owner_creation.rb in bcdd-process-0.3.0

- old
+ new

@@ -3,35 +3,32 @@ class Account class OwnerCreation < ::BCDD::Process include BCDD::Result::RollbackOnFailure input do - attribute :uuid, contract: :is_uuid, default: -> { ::SecureRandom.uuid }, normalize: -> { _1.strip.downcase } - attribute :owner, type: ::Hash, validate: :is_present + attribute :uuid, contract: :is_uuid, normalize: -> { _1.strip.downcase }, default: -> { ::SecureRandom.uuid } + attribute :owner, type: ::Hash, contract: :is_present end output do Failure( invalid_owner: ::Hash, - invalid_account: :errors_by_attribute, + invalid_account: :errors_by_attribute ) - user = contract[::User] & :is_persisted - account = contract[::Account] & :is_persisted - - Success(account_owner_created: { account:, user: }) + Success account_owner_created: { + user: contract[::User] & :is_persisted, + account: contract[::Account] & :is_persisted + } end def call(**input) - Given(input) - .then { |result| - rollback_on_failure { - result - .and_then(:create_owner) - .and_then(:create_account) - .and_then(:link_owner_to_account) - } - }.and_expose(:account_owner_created, %i[account user]) + rollback_on_failure { + Given(input) + .and_then(:create_owner) + .and_then(:create_account) + .and_then(:link_owner_to_account) + }.and_expose(:account_owner_created, %i[account user]) end private def create_owner(owner:, **)