Class: CarrierWave::Storage::ActiverecordStoreInModel::File

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave-activerecord-store-in-model/storage/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#fileObject (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

#urlObject

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_allObject



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

Returns:

  • (Boolean)


29
30
31
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 29

def blank?
  file.nil?
end

#content_typeObject



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

#deleteObject 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

#identifierObject



52
53
54
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 52

def identifier
  file.identifier if file
end

#original_filenameObject 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

#readObject



33
34
35
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 33

def read
  file.data if file
end

#sizeObject



37
38
39
# File 'lib/carrierwave-activerecord-store-in-model/storage/file.rb', line 37

def size
  file.size if file
end