Class: Royal::Transaction
- Inherits:
-
Object
- Object
- Royal::Transaction
- Defined in:
- lib/royal/transaction.rb
Defined Under Namespace
Classes: Operation
Instance Method Summary collapse
- #add_points(owner, amount, reason: nil, pointable: nil) ⇒ self
- #call ⇒ self
-
#initialize ⇒ Transaction
constructor
A new instance of Transaction.
- #subtract_points(owner, amount, reason: nil, pointable: nil) ⇒ self
Constructor Details
#initialize ⇒ Transaction
Returns a new instance of Transaction.
19 20 21 |
# File 'lib/royal/transaction.rb', line 19 def initialize @operations = [] end |
Instance Method Details
#add_points(owner, amount, reason: nil, pointable: nil) ⇒ self
28 29 30 31 32 |
# File 'lib/royal/transaction.rb', line 28 def add_points(owner, amount, reason: nil, pointable: nil) @operations << Operation.new(owner, amount, reason, pointable).freeze self end |
#call ⇒ self
44 45 46 47 48 49 50 |
# File 'lib/royal/transaction.rb', line 44 def call PointBalance.transaction(requires_new: true) do @operations.sort_by(&:sorting_key).each(&:perform) end self end |
#subtract_points(owner, amount, reason: nil, pointable: nil) ⇒ self
39 40 41 |
# File 'lib/royal/transaction.rb', line 39 def subtract_points(owner, amount, reason: nil, pointable: nil) add_points(owner, -amount, reason: reason, pointable: pointable) end |