module Gamification::Concerns::Models::Goal
Public Instance Methods
complete_for(subject)
click to toggle source
Complete the goal for the given subject.
subject - An ActiveRecord
model that can receive rewards.
# File lib/gamification/concerns/models/goal.rb, line 25 def complete_for subject if completed_by? subject raise Completed, "#{self} is already completed for #{subject}" else ::Gamification::Reward.create! goal: self, rewardable: subject end end
completed_by?(subject)
click to toggle source
Determine whether the given subject has completed the goal.
subject - An ActiveRecord
model that can receive rewards.
# File lib/gamification/concerns/models/goal.rb, line 18 def completed_by? subject !!reward_for(subject) end
Private Instance Methods
reward_for(rewardable)
click to toggle source
Find the Reward
for the given subject.
subject - A rewardable model.
# File lib/gamification/concerns/models/goal.rb, line 38 def reward_for rewardable rewards.find_by rewardable: rewardable end