Class: NotesFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/notes_finder.rb

Constant Summary collapse

FETCH_OVERLAP =
5.seconds

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user, params = {}) ⇒ NotesFinder

Used to filter Notes When used with target_type and target_id this returns notes specifically for the controller

Arguments:

current_user - which user check authorizations with
project - which project to look for notes on
params:
  target: noteable
  target_type: string
  target_id: integer
  last_fetched_at: time
  search: string
  sort: string


22
23
24
25
26
27
# File 'app/finders/notes_finder.rb', line 22

def initialize(current_user, params = {})
  @project = params[:project]
  @current_user = current_user
  @params = params.dup
  @target_type = @params[:target_type]
end

Instance Attribute Details

#target_typeObject (readonly)

Returns the value of attribute target_type.



6
7
8
# File 'app/finders/notes_finder.rb', line 6

def target_type
  @target_type
end

Instance Method Details

#executeObject



29
30
31
32
33
34
35
36
# File 'app/finders/notes_finder.rb', line 29

def execute
  notes = init_collection
  notes = since_fetch_at(notes)
  notes = notes.with_notes_filter(@params[:notes_filter]) if notes_filter?
  notes = redact_internal(notes)
  notes = notes.without_hidden if without_hidden_notes?
  sort(notes)
end

#targetObject



38
39
40
41
42
43
44
45
46
# File 'app/finders/notes_finder.rb', line 38

def target
  return @target if defined?(@target)

  if target_given?
    use_explicit_target
  else
    find_target_by_type_and_ids
  end
end