Sha256: a643ab56aee73b0268afc7d5028c0cac8c4920989fd3f22ae2e22e231714b635
Contents?: true
Size: 1.08 KB
Versions: 8
Compression:
Stored size: 1.08 KB
Contents
module StripeLocal class Balance < ActiveRecord::Base include ObjectAdapter @@cache ||= {} after_create do |record| @@cache = { current: record.available, pending: record.pending } end class<<self def available @@cache[:current] ||= all.pluck( :available ).last || 0 end alias :current :available def pending @@cache[:pending] ||= all.pluck( :pending ).last || 0 end def previous_available @@cache[:previous] ||= all.pluck( :available )[-2] || 0 end alias :previous :previous_available def previous_pending @@cache[:previous_pending] ||= all.pluck( :pending )[-2] || 0 end def changed @@cache[:changed] ||= ( self.current - self.previous ) end def event update if ( self.pending == update[:pending] ) && ( self.available == update[:available] ) Balance.last.touch else Balance.create( update ) end end end def to_s Balance.available.to_money end alias :inspect :to_s end end
Version data entries
8 entries across 8 versions & 1 rubygems