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 `Note` that can be resolvable.
%w(DiffNote DiscussionNote).freeze
Instance Method Summary collapse
-
#potentially_resolvable? ⇒ Boolean
Keep this method in sync with the `potentially_resolvable` scope.
-
#resolvable? ⇒ Boolean
Keep this method in sync with the `resolvable` scope.
- #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
36 37 38 |
# File 'app/models/concerns/resolvable_note.rb', line 36 def potentially_resolvable? RESOLVABLE_TYPES.include?(self.class.name) && noteable&.supports_resolvable_notes? end |
#resolvable? ⇒ Boolean
Keep this method in sync with the `resolvable` scope
41 42 43 |
# File 'app/models/concerns/resolvable_note.rb', line 41 def resolvable? potentially_resolvable? && !system? end |
#resolve!(current_user, resolved_by_push: false) ⇒ Object
78 79 80 81 |
# File 'app/models/concerns/resolvable_note.rb', line 78 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!`
56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/concerns/resolvable_note.rb', line 56 def resolve_without_save(current_user, resolved_by_push: false) return false unless resolvable? return false if resolved? self.resolved_at = Time.current self.resolved_by = current_user self.resolved_by_push = resolved_by_push true end |
#resolved? ⇒ Boolean
45 46 47 48 49 |
# File 'app/models/concerns/resolvable_note.rb', line 45 def resolved? return false unless resolvable? self.resolved_at.present? end |
#to_be_resolved? ⇒ Boolean
51 52 53 |
# File 'app/models/concerns/resolvable_note.rb', line 51 def to_be_resolved? resolvable? && !resolved? end |
#unresolve! ⇒ Object
83 84 85 |
# File 'app/models/concerns/resolvable_note.rb', line 83 def unresolve! unresolve_without_save && save! end |
#unresolve_without_save ⇒ Object
If you update this method remember to also update `.unresolve!`
68 69 70 71 72 73 74 75 76 |
# File 'app/models/concerns/resolvable_note.rb', line 68 def unresolve_without_save return false unless resolvable? return false unless resolved? self.resolved_at = nil self.resolved_by = nil true end |