Sha256: a7c3f2bb935a7d2ff2103af0fb24207478fdce4073d345e1f8eb866b48b8f722

Contents?: true

Size: 667 Bytes

Versions: 5

Compression:

Stored size: 667 Bytes

Contents

module Emotions
  class Emotion < ActiveRecord::Base
    self.table_name = 'emotions'

    # Validations
    validates :emotional, presence: true
    validates :emotive, presence: true
    validates_each :emotion do |record, attr, value|
      record.errors.add attr, 'invalid' unless Emotions.emotions.include?(value.try(:to_sym))
    end

    # Associations
    belongs_to :emotional, polymorphic: true
    belongs_to :emotive, polymorphic: true

    # Callbacks
    after_create :update_emotion_counter
    after_destroy :update_emotion_counter

  protected

    def update_emotion_counter
      self.emotive.update_emotion_counter(self.emotion)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
emotions-0.1.6 lib/emotions/emotion.rb
emotions-0.1.5 lib/emotions/emotion.rb
emotions-0.1.4 lib/emotions/emotion.rb
emotions-0.1.3 lib/emotions/emotion.rb
emotions-0.1.2 lib/emotions/emotion.rb