Sha256: deb4c101772408948d5db215d2a15cc09e98cf3fdebeb9da272f447183162da4

Contents?: true

Size: 670 Bytes

Versions: 8

Compression:

Stored size: 670 Bytes

Contents

module Gamification
  class Reward < ApplicationRecord
    belongs_to :goal
    belongs_to :rewardable, polymorphic: true, inverse_of: :rewards

    scope :unseen, -> { where seen_at: nil }
    scope :seen, -> { where.not seen_at: nil }

    scope :with_medals,    -> { all.select &:medal }
    scope :without_medals, -> { all.reject &:medal }

    validates :rewardable_id, uniqueness: { scope: [:rewardable_type, :goal] }

    delegate :points, to: :goal
    delegate :medal, to: :goal

    def see
      touch :seen_at
    end

    def seen?
      !!seen_at
    end

    class << self
      def see
        all.map { |reward| reward.see }
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
go_gamification-0.0.20 app/models/gamification/reward.rb
go_gamification-0.0.19 app/models/gamification/reward.rb
go_gamification-0.0.18 app/models/gamification/reward.rb
go_gamification-0.0.17 app/models/gamification/reward.rb
go_gamification-0.0.16 app/models/gamification/reward.rb
go_gamification-0.0.15 app/models/gamification/reward.rb
go_gamification-0.0.14 app/models/gamification/reward.rb
go_gamification-0.0.13 app/models/gamification/reward.rb