Sha256: 6d514a74682fae14b0cba39dc82bbb5894251de22c33ee43ee91d5420679658a
Contents?: true
Size: 766 Bytes
Versions: 7
Compression:
Stored size: 766 Bytes
Contents
class Transfer < CommandModel::Model parameter :from_name, :to_name, presence: true parameter :amount, typecast: :integer, presence: true, numericality: { greater_than: 0 } validate do |model| { from_name: from, to_name: to }.each do |key, value| errors.add key, "is not a valid account name" unless value end end validate do |model| errors.add :base, "From and to accounts cannot be the same" if model.from == model.to end def call if from.balance >= amount from.withdraw amount: amount to.deposit amount: amount else errors.add :amount, "is more than account balance" end end def from Account.find_by_name from_name end def to Account.find_by_name to_name end end
Version data entries
7 entries across 7 versions & 1 rubygems