Class: CarrierWave::Storage::DirectDatabase::File

Inherits:
Object
  • Object
show all
Defined in:
app/uploaders/polymorphic_uploader.rb

Overview

rubocop:todo Style/Documentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uploader, base, path) ⇒ File

Returns a new instance of File.


20
21
22
23
24
# File 'app/uploaders/polymorphic_uploader.rb', line 20

def initialize(uploader, base, path)
  @uploader = uploader
  @path = path
  @base = base
end

Instance Attribute Details

#pathObject (readonly)

Returns the current path of the file


27
28
29
# File 'app/uploaders/polymorphic_uploader.rb', line 27

def path
  @path
end

Instance Method Details

#content_typeObject

Error handling should help if uploader was mounted to a model with no content_type


52
53
54
# File 'app/uploaders/polymorphic_uploader.rb', line 52

def content_type
  @uploader.model.content_type if @uploader.model.respond_to? :content_type
end

#content_type=(type) ⇒ Object


56
57
58
59
60
# File 'app/uploaders/polymorphic_uploader.rb', line 56

def content_type=(type)
  if @uploader.model.respond_to? :content_type
    @uploader.model.content_type = type unless type.nil?
  end
end

#deleteObject

Remove the file


37
38
39
# File 'app/uploaders/polymorphic_uploader.rb', line 37

def delete
  destroy_file
end

#readObject

Reads the contents of the file


32
33
34
# File 'app/uploaders/polymorphic_uploader.rb', line 32

def read
  current_data
end

#store(file) ⇒ Object

Stores the file in the DbFiles model - split across many rows if size > 200KB


47
48
49
# File 'app/uploaders/polymorphic_uploader.rb', line 47

def store(file)
  @uploader.model.db_files.create!(data: file)
end

#urlObject

Would returns the url

Raises:

  • (NotImplementedError)

42
43
44
# File 'app/uploaders/polymorphic_uploader.rb', line 42

def url
  raise NotImplementedError, 'Files are stored in the database, so are not available directly through a URL'
end