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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (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_typeObject

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

#deleteObject

Remove the file



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

def delete
  destroy_file
end

#readObject

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

#urlObject

Would returns the url

Raises:

  • (NotImplementedError)


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