Skip to content

Instantly share code, notes, and snippets.

@pdx91
Last active March 31, 2024 00:03
Show Gist options
  • Save pdx91/1c82640957732d454ef5a6af262b2c46 to your computer and use it in GitHub Desktop.
Save pdx91/1c82640957732d454ef5a6af262b2c46 to your computer and use it in GitHub Desktop.
BalanceHistory::Preservation
# This class in pulled from https://balance.day for my 37signals application.
class BalanceHistory::Preservation
InvalidData = Class.new(StandardError)
attr_reader :account
def initialize(account)
@account = account
end
def preserve!
strategy.perform!
end
private
def strategy
if investment_account? && investment_strategy_enabled?
Strategy::PortfolioValue.new(account)
else
Strategy::AccountBalance.new(account)
end
end
def investment_account?
account.account_type.investment? && account.holdings.present?
end
def investment_strategy_enabled?
System.investments_enabled?(account.user)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment