From cc656a11992483911cefe035d579096581cfde57 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 6 Apr 2017 10:05:57 -0500 Subject: Refactor resolvability checks based on type --- app/models/concerns/noteable.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'app/models/concerns/noteable.rb') diff --git a/app/models/concerns/noteable.rb b/app/models/concerns/noteable.rb index 631df4757a4..772ff6a6d2f 100644 --- a/app/models/concerns/noteable.rb +++ b/app/models/concerns/noteable.rb @@ -1,4 +1,29 @@ module Noteable + # Names of all implementers of `Noteable` that support resolvable notes. + RESOLVABLE_TYPES = %w(MergeRequest).freeze + + def base_class_name + self.class.base_class.name + end + + # Convert this Noteable class name to a format usable by notifications. + # + # Examples: + # + # noteable.class # => MergeRequest + # noteable.human_class_name # => "merge request" + def human_class_name + @human_class_name ||= base_class_name.titleize.downcase + end + + def supports_resolvable_notes? + RESOLVABLE_TYPES.include?(base_class_name) + end + + def supports_discussions? + DiscussionNote::NOTEABLE_TYPES.include?(base_class_name) + end + def discussion_notes notes end -- cgit v1.2.1