module Emotions::Emotion

Protected Instance Methods

ensure_valid_associated_record(association) click to toggle source

Make sure that both emotive and emotional records are actually able to express and/or receive emotions

# File lib/emotions/emotion.rb, line 41
def ensure_valid_associated_record(association)
  value = send(association)
  predicate = :"#{association}?"

  if !value.class.respond_to?(predicate) || !value.class.send(predicate)
    errors.add association, I18n.t(:invalid, scope: [:errors, :messages])
  end
end
ensure_valid_emotion_name() click to toggle source

Make sure we’re using an allowed emotion name

# File lib/emotions/emotion.rb, line 33
def ensure_valid_emotion_name
  unless Emotions.emotions.include?(emotion.try(:to_sym))
    errors.add :emotion, I18n.t(:invalid, scope: [:errors, :messages])
  end
end
update_emotion_counter() click to toggle source

Update the ‘<emotion>_emotions_counter` for the emotive record

# File lib/emotions/emotion.rb, line 27
def update_emotion_counter
  emotive.update_emotion_counter(emotion)
  emotional.update_emotion_counter(emotion)
end