Module: Royal::Points
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/royal/points.rb
Instance Method Summary collapse
-
#add_points(amount, reason: nil, pointable: nil) ⇒ Integer
Adds a number of points to the record’s current points balance.
-
#current_points ⇒ Integer
Returns the current number of points in the record’s balance.
-
#subtract_points(amount, reason: nil, pointable: nil) ⇒ Integer
Subtracts a number of points to the record’s current points balance.
Instance Method Details
#add_points(amount, reason: nil, pointable: nil) ⇒ Integer
Adds a number of points to the record’s current points balance.
27 28 29 |
# File 'lib/royal/points.rb', line 27 def add_points(amount, reason: nil, pointable: nil) point_balances.apply_change_to_points(self, amount, reason: reason, pointable: pointable) end |
#current_points ⇒ Integer
Returns the current number of points in the record’s balance.
17 18 19 |
# File 'lib/royal/points.rb', line 17 def current_points point_balances.order(sequence: :desc).limit(1).pluck(:balance).first || 0 end |
#subtract_points(amount, reason: nil, pointable: nil) ⇒ Integer
Subtracts a number of points to the record’s current points balance.
37 38 39 |
# File 'lib/royal/points.rb', line 37 def subtract_points(amount, reason: nil, pointable: nil) point_balances.apply_change_to_points(self, -amount, reason: reason, pointable: pointable) end |