Module: ResolvableNote
- Extended by:
- ActiveSupport::Concern
- Included in:
- Note
- Defined in:
- app/models/concerns/resolvable_note.rb
Constant Summary collapse
- RESOLVABLE_TYPES =
Names of all subclasses of
Notethat can be resolvable. %w[DiffNote DiscussionNote].freeze
Instance Method Summary collapse
-
#potentially_resolvable? ⇒ Boolean
Keep this method in sync with the
potentially_resolvablescope. -
#resolvable? ⇒ Boolean
Keep this method in sync with the
resolvablescope. - #resolve!(current_user, resolved_by_push: false) ⇒ Object
-
#resolve_without_save(current_user, resolved_by_push: false) ⇒ Object
If you update this method remember to also update
.resolve!. - #resolved? ⇒ Boolean
- #to_be_resolved? ⇒ Boolean
- #unresolve! ⇒ Object
-
#unresolve_without_save ⇒ Object
If you update this method remember to also update
.unresolve!.
Instance Method Details
#potentially_resolvable? ⇒ Boolean
Keep this method in sync with the potentially_resolvable scope
47 48 49 |
# File 'app/models/concerns/resolvable_note.rb', line 47 def potentially_resolvable? self.class.resolvable_types.include?(self.class.name) && noteable&.supports_resolvable_notes? end |
#resolvable? ⇒ Boolean
Keep this method in sync with the resolvable scope
52 53 54 |
# File 'app/models/concerns/resolvable_note.rb', line 52 def resolvable? potentially_resolvable? && !system? end |
#resolve!(current_user, resolved_by_push: false) ⇒ Object
92 93 94 95 |
# File 'app/models/concerns/resolvable_note.rb', line 92 def resolve!(current_user, resolved_by_push: false) resolve_without_save(current_user, resolved_by_push: resolved_by_push) && save! end |
#resolve_without_save(current_user, resolved_by_push: false) ⇒ Object
If you update this method remember to also update .resolve!
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/concerns/resolvable_note.rb', line 67 def resolve_without_save(current_user, resolved_by_push: false) return false unless resolvable? return false if resolved? now = Time.current self.updated_at = now self.resolved_at = now self.resolved_by = current_user self.resolved_by_push = resolved_by_push true end |
#resolved? ⇒ Boolean
56 57 58 59 60 |
# File 'app/models/concerns/resolvable_note.rb', line 56 def resolved? return false unless resolvable? self.resolved_at.present? end |
#to_be_resolved? ⇒ Boolean
62 63 64 |
# File 'app/models/concerns/resolvable_note.rb', line 62 def to_be_resolved? resolvable? && !resolved? end |
#unresolve! ⇒ Object
97 98 99 |
# File 'app/models/concerns/resolvable_note.rb', line 97 def unresolve! unresolve_without_save && save! end |
#unresolve_without_save ⇒ Object
If you update this method remember to also update .unresolve!
81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/concerns/resolvable_note.rb', line 81 def unresolve_without_save return false unless resolvable? return false unless resolved? self.updated_at = Time.current self.resolved_at = nil self.resolved_by = nil true end |