Class: CarrierWave::Storage::ActiverecordStoreInModel::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::ActiverecordStoreInModel::File
- Defined in:
- lib/carrierwave-activerecord-store-in-model/storage/file.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .create!(new_file, identifier, store_dir) ⇒ Object
- .delete_all ⇒ Object
- .fetch!(identifier) ⇒ Object
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #content_type ⇒ Object
- #content_type=(content_type) ⇒ Object
- #delete ⇒ Object (also: #destroy!)
- #identifier ⇒ Object
-
#initialize(file = nil) ⇒ File
constructor
A new instance of File.
- #original_filename ⇒ Object (also: #filename)
- #read ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(file = nil) ⇒ File
Returns a new instance of File.
25 26 27 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 25 def initialize(file = nil) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
22 23 24 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 22 def file @file end |
#url ⇒ Object
Returns the value of attribute url.
23 24 25 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 23 def url @url end |
Class Method Details
.create!(new_file, identifier, store_dir) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 5 def self.create!(new_file, identifier, store_dir) attributes = { :identifier => identifier, :original_filename => new_file.original_filename, :content_type => new_file.content_type, :size => new_file.size, :data => new_file.read } self.new ActiveRecordFile.new store_dir, attributes end |
.delete_all ⇒ Object
18 19 20 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 18 def self.delete_all ActiveRecordFile.delete_all end |
.fetch!(identifier) ⇒ Object
14 15 16 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 14 def self.fetch! identifier self.new ActiveRecordFile.find_by_identifier! identifier end |
Instance Method Details
#blank? ⇒ Boolean
29 30 31 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 29 def blank? file.nil? end |
#content_type ⇒ Object
41 42 43 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 41 def content_type file.content_type if file end |
#content_type=(content_type) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 45 def content_type= content_type if file file.content_type = content_type file.save end end |
#delete ⇒ Object Also known as: destroy!
61 62 63 64 65 66 67 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 61 def delete if file file.destroy else false end end |
#identifier ⇒ Object
52 53 54 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 52 def identifier file.identifier if file end |
#original_filename ⇒ Object Also known as: filename
56 57 58 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 56 def original_filename file.original_filename if file end |
#read ⇒ Object
33 34 35 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 33 def read file.data if file end |
#size ⇒ Object
37 38 39 |
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 37 def size file.size if file end |