Class: CarrierWave::Storage::DirectDatabase::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::DirectDatabase::File
- Defined in:
- app/uploaders/polymorphic_uploader.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the current path of the file.
Instance Method Summary collapse
-
#content_type ⇒ Object
Error handling should help if uploader was mounted to a model with no content_type.
- #content_type=(type) ⇒ Object
-
#delete ⇒ Object
Remove the file.
-
#initialize(uploader, base, path) ⇒ File
constructor
A new instance of File.
-
#read ⇒ Object
Reads the contents of the file.
-
#store(file) ⇒ Object
Stores the file in the DbFiles model - split across many rows if size > 200KB.
-
#url ⇒ Object
Would returns the url.
Constructor Details
#initialize(uploader, base, path) ⇒ File
Returns a new instance of File.
21 22 23 24 25 |
# File 'app/uploaders/polymorphic_uploader.rb', line 21 def initialize(uploader, base, path) @uploader = uploader @path = path @base = base end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the current path of the file
28 29 30 |
# File 'app/uploaders/polymorphic_uploader.rb', line 28 def path @path end |
Instance Method Details
#content_type ⇒ Object
Error handling should help if uploader was mounted to a model with no content_type
53 54 55 |
# File 'app/uploaders/polymorphic_uploader.rb', line 53 def content_type @uploader.model.content_type if @uploader.model.respond_to? :content_type end |
#content_type=(type) ⇒ Object
57 58 59 |
# File 'app/uploaders/polymorphic_uploader.rb', line 57 def content_type=(type) @uploader.model.content_type = type unless type.nil? if @uploader.model.respond_to? :content_type end |
#delete ⇒ Object
Remove the file
38 39 40 |
# File 'app/uploaders/polymorphic_uploader.rb', line 38 def delete destroy_file end |
#read ⇒ Object
Reads the contents of the file
33 34 35 |
# File 'app/uploaders/polymorphic_uploader.rb', line 33 def read current_data end |
#store(file) ⇒ Object
Stores the file in the DbFiles model - split across many rows if size > 200KB
48 49 50 |
# File 'app/uploaders/polymorphic_uploader.rb', line 48 def store(file) @uploader.model.db_files.create!(data: file) end |
#url ⇒ Object
Would returns the url
43 44 45 |
# File 'app/uploaders/polymorphic_uploader.rb', line 43 def url raise NotImplementedError, 'Files are stored in the database, so are not available directly through a URL' end |