Sha256: d587972759e9bd6e1d39d730de129247603a938f76c40d85f5fe0a156d6768e2
Contents?: true
Size: 1.22 KB
Versions: 76
Compression:
Stored size: 1.22 KB
Contents
module Feedback class Feedback < ApplicationRecord scope :created_after, ->(date) { where('feedback_feedbacks.created_at >= ?', date) if date.present? } scope :created_before, ->(date) { where('feedback_feedbacks.created_at <= ?', date) if date.present? } scope :created_between, ->(start_date, end_date) { created_after(start_date).created_before(end_date) } belongs_to :resource, class_name: '::Feedback::Resource' belongs_to :owner, polymorphic: true belongs_to :config, optional: true, class_name: '::Feedback::Config', foreign_key: 'feedback_config_id', inverse_of: :feedbacks attr_accessor :email, :source before_validation :set_resource validates :sentiment, presence: true validates :owner, presence: true scope :positive, -> { where(sentiment: 'positive') } scope :negative, -> { where(sentiment: 'negative') } scope :neutral, -> { where(sentiment: 'neutral') } after_commit :notify def set_resource self.resource ||= Resource.find_or_create_by!(uri: source) end def notify OrbitFeedbackNotifier.call(self) if !owner.nil? && owner.email.present? return unless ENV['SLACK_WEBHOOK'] FeedbackSlackNotifier.call(self) end end end
Version data entries
76 entries across 76 versions & 1 rubygems