ExDoubleEntry.Guard (ExDoubleEntry v0.1.0) View Source
Link to this section Summary
Functions
Examples
iex> %Transfer{ iex> money: Money.new(42, :USD), iex> from: %Account{identifier: :checking, currency: :USD}, iex> to: %Account{identifier: :savings, currency: :USD}, iex> code: :deposit iex> } iex> |> Guard.matching_currency?() { :ok, %Transfer{
Examples
iex> %Transfer{money: Money.new(42, :USD), from: nil, to: nil, code: nil} iex> |> Guard.positive_amount?() {:ok, %Transfer{money: Money.new(42, :USD), from: nil, to: nil, code: nil}}
Examples
iex> %Transfer{ iex> money: Money.new(42, :USD), iex> from: %Account{identifier: :checking, currency: :USD, balance: Money.new(42, :USD), positive_only?: true}, iex> to: %Account{identifier: :savings, currency: :USD}, iex> code: :deposit iex> } iex> |> Guard.positive_balance_if_enforced?() { :ok, %Transfer{
Examples
iex> %Transfer{ iex> money: nil, iex> from: %Account{identifier: :checking, currency: :USD}, iex> to: %Account{identifier: :savings, currency: :USD}, iex> code: :deposit iex> } iex> |> Guard.valid_definition?() { :ok, %Transfer{
Link to this section Functions
Examples
iex> %Transfer{ iex> money: Money.new(42, :USD), iex> from: %Account{identifier: :checking, currency: :USD}, iex> to: %Account{identifier: :savings, currency: :USD}, iex> code: :deposit iex> } iex> |> Guard.matching_currency?() { :ok, %Transfer{
money: Money.new(42, :USD),
code: :deposit,
from: %Account{identifier: :checking, currency: :USD},
to: %Account{identifier: :savings, currency: :USD},
} }
iex> %Transfer{ iex> money: Money.new(42, :AUD), iex> from: %Account{identifier: :checking, currency: :USD}, iex> to: %Account{identifier: :savings, currency: :USD}, iex> code: :deposit iex> } iex> |> Guard.matching_currency?()
iex> %Transfer{ iex> money: Money.new(42, :USD), iex> from: %Account{identifier: :checking, currency: :USD}, iex> to: %Account{identifier: :savings, currency: :AUD}, iex> code: :deposit iex> } iex> |> Guard.matching_currency?()
Examples
iex> %Transfer{money: Money.new(42, :USD), from: nil, to: nil, code: nil} iex> |> Guard.positive_amount?() {:ok, %Transfer{money: Money.new(42, :USD), from: nil, to: nil, code: nil}}
iex> %Transfer{money: Money.new(-42, :USD), from: nil, to: nil, code: nil} iex> |> Guard.positive_amount?()
Examples
iex> %Transfer{ iex> money: Money.new(42, :USD), iex> from: %Account{identifier: :checking, currency: :USD, balance: Money.new(42, :USD), positive_only?: true}, iex> to: %Account{identifier: :savings, currency: :USD}, iex> code: :deposit iex> } iex> |> Guard.positive_balance_if_enforced?() { :ok, %Transfer{
money: Money.new(42, :USD),
code: :deposit,
from: %Account{identifier: :checking, currency: :USD, balance: Money.new(42, :USD), positive_only?: true},
to: %Account{identifier: :savings, currency: :USD},
} }
iex> %Transfer{ iex> money: Money.new(42, :USD), iex> from: %Account{identifier: :checking, currency: :USD, balance: Money.new(10, :USD), positive_only?: false}, iex> to: %Account{identifier: :savings, currency: :USD}, iex> code: :deposit iex> } iex> |> Guard.positive_balance_if_enforced?() { :ok, %Transfer{
money: Money.new(42, :USD),
code: :deposit,
from: %Account{identifier: :checking, currency: :USD, balance: Money.new(10, :USD), positive_only?: false},
to: %Account{identifier: :savings, currency: :USD},
} }
iex> %Transfer{ iex> money: Money.new(42, :USD), iex> from: %Account{identifier: :checking, currency: :USD, balance: Money.new(10, :USD)}, iex> to: %Account{identifier: :savings, currency: :USD}, iex> code: :deposit iex> } iex> |> Guard.positive_balance_if_enforced?() { :ok, %Transfer{
money: Money.new(42, :USD),
code: :deposit,
from: %Account{identifier: :checking, currency: :USD, balance: Money.new(10, :USD), positive_only?: nil},
to: %Account{identifier: :savings, currency: :USD},
} }
iex> %Transfer{ iex> money: Money.new(42, :USD), iex> from: %Account{identifier: :checking, currency: :USD, balance: Money.new(10, :USD), positive_only?: true}, iex> to: %Account{identifier: :savings, currency: :USD}, iex> code: :deposit iex> } iex> |> Guard.positive_balance_if_enforced?()
Examples
iex> %Transfer{ iex> money: nil, iex> from: %Account{identifier: :checking, currency: :USD}, iex> to: %Account{identifier: :savings, currency: :USD}, iex> code: :deposit iex> } iex> |> Guard.valid_definition?() { :ok, %Transfer{
money: nil,
code: :deposit,
from: %Account{identifier: :checking, currency: :USD},
to: %Account{identifier: :savings, currency: :USD},
} }
iex> %Transfer{ iex> money: nil, iex> from: %Account{identifier: :checking, currency: :USD}, iex> to: %Account{identifier: :savings, currency: :USD}, iex> code: :give_away iex> } iex> |> Guard.valid_definition?()
iex> %Transfer{ iex> money: nil, iex> from: %Account{identifier: :checking, currency: :USD}, iex> to: %Account{identifier: :savings, currency: :USD}, iex> code: :withdraw iex> } iex> |> Guard.valid_definition?()