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


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


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

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

#content_type=(type) ⇒ Object


61
62
63
64
65
# File 'app/uploaders/polymorphic_uploader.rb', line 61

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
50
51
52
53
54
# File 'app/uploaders/polymorphic_uploader.rb', line 47

def store(file)
  each_slice(file) do |start, finish|
    @uploader.model.db_files.create!(data: file.slice(start, finish))
  end

  # Old code from attachment_fu: doesn't seem to be needed
  # #  self.class.update_all ['db_file_id = ?', self.db_file_id = db_file.id], ['id = ?', id]
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