Class: StripeLocal::Balance

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ObjectAdapter
Defined in:
app/models/stripe_local/balance.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.availableObject Also known as: current



11
12
13
# File 'app/models/stripe_local/balance.rb', line 11

def available
  @@cache[:current] ||= all.pluck( :available ).last || 0
end

.changedObject



29
30
31
# File 'app/models/stripe_local/balance.rb', line 29

def changed
  @@cache[:changed] ||= ( self.current - self.previous )
end

.event(update) ⇒ Object



33
34
35
36
37
38
39
# File 'app/models/stripe_local/balance.rb', line 33

def event update
  if ( self.pending == update[:pending] ) && ( self.available == update[:available] )
    Balance.last.touch
  else
    Balance.create( update )
  end
end

.pendingObject



16
17
18
# File 'app/models/stripe_local/balance.rb', line 16

def pending
  @@cache[:pending] ||= all.pluck( :pending ).last || 0
end

.previous_availableObject Also known as: previous



20
21
22
# File 'app/models/stripe_local/balance.rb', line 20

def previous_available
  @@cache[:previous] ||= all.pluck( :available )[-2] || 0
end

.previous_pendingObject



25
26
27
# File 'app/models/stripe_local/balance.rb', line 25

def previous_pending
  @@cache[:previous_pending] ||= all.pluck( :pending )[-2] || 0
end

Instance Method Details

#to_sObject Also known as: inspect



42
43
44
# File 'app/models/stripe_local/balance.rb', line 42

def to_s
  Balance.available.to_money
end