Class: Banzai::UploadsFinder

Inherits:
Object
  • Object
show all
Includes:
FinderMethods
Defined in:
app/finders/banzai/uploads_finder.rb

Instance Method Summary collapse

Methods included from FinderMethods

#find, #find_by, #find_by!

Constructor Details

#initialize(parent:) ⇒ UploadsFinder

Returns a new instance of UploadsFinder.



7
8
9
# File 'app/finders/banzai/uploads_finder.rb', line 7

def initialize(parent:)
  @parent = parent
end

Instance Method Details

#executeObject



11
12
13
14
15
16
# File 'app/finders/banzai/uploads_finder.rb', line 11

def execute
  Upload
    .for_model_type_and_id(@parent.class.polymorphic_name, @parent.id)
    .for_uploader(uploader_class)
    .order_by_created_at_desc
end

#find_by_secret_and_filename(secret, filename) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'app/finders/banzai/uploads_finder.rb', line 18

def find_by_secret_and_filename(secret, filename)
  return unless secret && filename

  uploader = uploader_class.new(@parent, secret: secret)
  upload_paths = uploader.upload_paths(filename)

  execute.without_order.find_by_path(upload_paths)
rescue FileUploader::InvalidSecret
  nil
end