Module: ResolvableDiscussion

Extended by:
ActiveSupport::Concern
Includes:
Gitlab::Utils::StrongMemoize
Included in:
Discussion
Defined in:
app/models/concerns/resolvable_discussion.rb

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Instance Method Details

#can_resolve?(current_user) ⇒ Boolean

Returns:

  • (Boolean)

83
84
85
86
87
88
# File 'app/models/concerns/resolvable_discussion.rb', line 83

def can_resolve?(current_user)
  return false unless current_user
  return false unless resolvable?

  current_user.can?(:resolve_note, self.noteable)
end

#clear_memoized_valuesObject


102
103
104
105
106
# File 'app/models/concerns/resolvable_discussion.rb', line 102

def clear_memoized_values
  self.class.memoized_values.each do |name|
    clear_memoization(name)
  end
end

#first_noteObject


53
54
55
56
57
# File 'app/models/concerns/resolvable_discussion.rb', line 53

def first_note
  strong_memoize(:first_note) do
    notes.first
  end
end

#first_note_to_resolveObject


59
60
61
62
63
64
65
# File 'app/models/concerns/resolvable_discussion.rb', line 59

def first_note_to_resolve
  return unless resolvable?

  strong_memoize(:first_note_to_resolve) do
    notes.find(&:to_be_resolved?)
  end
end

#last_resolved_noteObject


67
68
69
70
71
72
73
# File 'app/models/concerns/resolvable_discussion.rb', line 67

def last_resolved_note
  return unless resolved?

  strong_memoize(:last_resolved_note) do
    resolved_notes.max_by(&:resolved_at)
  end
end

#resolvable?Boolean

Returns:

  • (Boolean)

41
42
43
44
45
# File 'app/models/concerns/resolvable_discussion.rb', line 41

def resolvable?
  strong_memoize(:resolvable) do
    potentially_resolvable? && notes.any?(&:resolvable?)
  end
end

#resolve!(current_user) ⇒ Object


90
91
92
93
94
# File 'app/models/concerns/resolvable_discussion.rb', line 90

def resolve!(current_user)
  return unless resolvable?

  update { |notes| notes.resolve!(current_user) }
end

#resolved?Boolean

Returns:

  • (Boolean)

47
48
49
50
51
# File 'app/models/concerns/resolvable_discussion.rb', line 47

def resolved?
  strong_memoize(:resolved) do
    resolvable? && notes.none?(&:to_be_resolved?)
  end
end

#resolved_by_push?Boolean

Returns:

  • (Boolean)

37
38
39
# File 'app/models/concerns/resolvable_discussion.rb', line 37

def resolved_by_push?
  !!last_resolved_note&.resolved_by_push?
end

#resolved_notesObject


75
76
77
# File 'app/models/concerns/resolvable_discussion.rb', line 75

def resolved_notes
  notes.select(&:resolved?)
end

#to_be_resolved?Boolean

Returns:

  • (Boolean)

79
80
81
# File 'app/models/concerns/resolvable_discussion.rb', line 79

def to_be_resolved?
  resolvable? && !resolved?
end

#unresolve!Object


96
97
98
99
100
# File 'app/models/concerns/resolvable_discussion.rb', line 96

def unresolve!
  return unless resolvable?

  update { |notes| notes.unresolve! }
end