mysociety/alaveteli

View on GitHub
app/models/concerns/notable.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Notable
  extend ActiveSupport::Concern

  included do
    has_many :concrete_notes,
             class_name: 'Note',
             as: :notable,
             inverse_of: :notable,
             dependent: :destroy
  end

  def all_notes
    notes = concrete_notes.with_translations
    return notes.to_a unless Taggable.models.include?(self.class)

    notes + tagged_notes.with_translations
  end

  def tagged_notes
    Note.where(notable_tag: notable_tags)
  end

  private

  def notable_tags
    tags.map(&:name_and_value)
  end
end