Class: Royal::PointBalance
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Royal::PointBalance
- Defined in:
- lib/royal/point_balance.rb
Class Method Summary collapse
-
.apply_change_to_points(owner, amount, **attributes) ⇒ Integer
Returns the new points balance.
- .latest_for_owner(owner) ⇒ PointBalance?
- .with_lock_on_owner(owner, &block) ⇒ Object
Instance Method Summary collapse
-
#original_balance ⇒ Integer
Returns the balance before this operation.
Class Method Details
.apply_change_to_points(owner, amount, **attributes) ⇒ Integer
Returns the new points balance.
43 44 45 46 47 |
# File 'lib/royal/point_balance.rb', line 43 def self.apply_change_to_points(owner, amount, **attributes) with_lock_on_owner(owner) do create!(owner: owner, amount: amount, **attributes).balance end end |
.latest_for_owner(owner) ⇒ PointBalance?
30 31 32 |
# File 'lib/royal/point_balance.rb', line 30 def self.latest_for_owner(owner) PointBalance.where(owner: owner).order(:sequence).last end |
Instance Method Details
#original_balance ⇒ Integer
Returns the balance before this operation.
52 53 54 |
# File 'lib/royal/point_balance.rb', line 52 def original_balance balance - amount end |