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
37 38 39 |
# File 'app/models/concerns/resolvable_note.rb', line 37 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
42 43 44 |
# File 'app/models/concerns/resolvable_note.rb', line 42 def resolvable? potentially_resolvable? && !system? end |
#resolve!(current_user, resolved_by_push: false) ⇒ Object
82 83 84 85 |
# File 'app/models/concerns/resolvable_note.rb', line 82 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!`
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/concerns/resolvable_note.rb', line 57 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
46 47 48 49 50 |
# File 'app/models/concerns/resolvable_note.rb', line 46 def resolved? return false unless resolvable? self.resolved_at.present? end |
#to_be_resolved? ⇒ Boolean
52 53 54 |
# File 'app/models/concerns/resolvable_note.rb', line 52 def to_be_resolved? resolvable? && !resolved? end |
#unresolve! ⇒ Object
87 88 89 |
# File 'app/models/concerns/resolvable_note.rb', line 87 def unresolve! unresolve_without_save && save! end |
#unresolve_without_save ⇒ Object
If you update this method remember to also update ‘.unresolve!`
71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/concerns/resolvable_note.rb', line 71 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 |