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

Version Path
station-0.5.16 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.15 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.14 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.13 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.12 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.11 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.10 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.9 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.8 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.7 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.6 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.5 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.4 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.3 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.2 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.1 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.5.0 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.4.9 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.4.8 lib/nexmo_developer/app/models/feedback/feedback.rb
station-0.4.7 lib/nexmo_developer/app/models/feedback/feedback.rb