Class: AsyncPaperclipUploader::Temporary

Inherits:
Object
  • Object
show all
Defined in:
lib/async_paperclip_uploader/temporary.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, attribute, uploaded_file) ⇒ Temporary

Returns a new instance of Temporary.



3
4
5
6
7
# File 'lib/async_paperclip_uploader/temporary.rb', line 3

def initialize(object, attribute, uploaded_file)
  @object = object
  @attribute = attribute
  @uploaded_file = uploaded_file
end

Class Method Details

.base_pathObject



35
36
37
# File 'lib/async_paperclip_uploader/temporary.rb', line 35

def self.base_path
  ENV["FILE_UPLOAD_STAGING_DIR"]
end

Instance Method Details

#callObject



9
10
11
12
13
14
# File 'lib/async_paperclip_uploader/temporary.rb', line 9

def call
  if valid?
    upload
    run_permanent_upload_job
  end
end

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/async_paperclip_uploader/temporary.rb', line 16

def valid?
  valid_class_attr? && valid_attachment? 
end

#valid_attachment?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
# File 'lib/async_paperclip_uploader/temporary.rb', line 24

def valid_attachment?
  attachment = {
    :filename => @uploaded_file[:filename],
    :content_type => @uploaded_file[:type],
    :headers => @uploaded_file[:head],
    :tempfile => @uploaded_file[:tempfile]
  }
  @object.send("#{@attribute}=", ActionDispatch::Http::UploadedFile.new(attachment))
  @object.valid?
end

#valid_class_attr?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/async_paperclip_uploader/temporary.rb', line 20

def valid_class_attr?
  @object.respond_to?(@attribute.to_sym)
end