Sha256: 0dc52b90c6291910bff5c46f2725593bdae332aaf1333b4b991731de7e6560b5

Contents?: true

Size: 1.08 KB

Versions: 11

Compression:

Stored size: 1.08 KB

Contents

module SocialNetworking
  # A sign of approval of a piece of content by a Participant.
  class Like < ActiveRecord::Base
    belongs_to :participant
    belongs_to :item, polymorphic: true

    validates :participant, :item, presence: true
    # a Participant may only Like an item once
    validates :item_id, uniqueness: { scope: [:item_type, :participant_id] }

    scope :for_today,
          lambda {
            where(arel_table[:created_at]
                    .gteq(Date.today.beginning_of_day)
                    .and(arel_table[:created_at].lteq(Date.today.end_of_day)))
          }

    scope :for_week,
          lambda {
            where(arel_table[:created_at]
                    .gteq(Time.current.advance(days: -7).beginning_of_day))
          }

    def item_description
      case item_type
      when "SocialNetworking::OnTheMindStatement"
        Shareable.new(item).description
      when "SocialNetworking::SharedItem"
        if item
          Shareable.new(item.item).description
        else
          Shareable.new(nil).description
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
social_networking-0.11.8 app/models/social_networking/like.rb
social_networking-0.11.7 app/models/social_networking/like.rb
social_networking-0.11.6 app/models/social_networking/like.rb
social_networking-0.11.5 app/models/social_networking/like.rb
social_networking-0.11.4 app/models/social_networking/like.rb
social_networking-0.11.3 app/models/social_networking/like.rb
social_networking-0.11.2 app/models/social_networking/like.rb
social_networking-0.11.1 app/models/social_networking/like.rb
social_networking-0.11.0 app/models/social_networking/like.rb
social_networking-0.10.0 app/models/social_networking/like.rb
social_networking-0.9.3 app/models/social_networking/like.rb