Class: Gamification::Goal
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Gamification::Goal
- Defined in:
- app/models/gamification/goal.rb
Instance Method Summary collapse
-
#complete_for(subject) ⇒ Object
Complete the goal for the given subject.
-
#completed_by?(subject) ⇒ Boolean
Determine whether the given subject has completed the goal.
Instance Method Details
#complete_for(subject) ⇒ Object
Complete the goal for the given subject.
subject - An ActiveRecord model that can receive rewards.
23 24 25 26 27 28 29 |
# File 'app/models/gamification/goal.rb', line 23 def complete_for subject if completed_by? subject raise Completed, "#{self} is already completed for #{subject}" else Reward.create! goal: self, rewardable: subject end end |
#completed_by?(subject) ⇒ Boolean
Determine whether the given subject has completed the goal.
subject - An ActiveRecord model that can receive rewards.
16 17 18 |
# File 'app/models/gamification/goal.rb', line 16 def completed_by? subject !!reward_for(subject) end |