Class: CarrierWave::Storage::PostgresqlLo::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::PostgresqlLo::File
- Defined in:
- lib/carrierwave/storage/postgresql_lo.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #content_type ⇒ Object
- #delete ⇒ Object
- #file_length ⇒ Object (also: #size)
- #identifier ⇒ Object
-
#initialize(uploader) ⇒ File
constructor
A new instance of File.
- #original_filename ⇒ Object
- #read ⇒ Object
- #url ⇒ Object
- #write(file) ⇒ Object
Constructor Details
#initialize(uploader) ⇒ File
Returns a new instance of File.
6 7 8 |
# File 'lib/carrierwave/storage/postgresql_lo.rb', line 6 def initialize(uploader) @uploader = uploader end |
Instance Method Details
#connection ⇒ Object
50 51 52 |
# File 'lib/carrierwave/storage/postgresql_lo.rb', line 50 def connection @connection ||= @uploader.model.connection.raw_connection end |
#content_type ⇒ Object
36 37 |
# File 'lib/carrierwave/storage/postgresql_lo.rb', line 36 def content_type end |
#delete ⇒ Object
32 33 34 |
# File 'lib/carrierwave/storage/postgresql_lo.rb', line 32 def delete connection.lo_unlink(identifier) end |
#file_length ⇒ Object Also known as: size
39 40 41 42 43 44 45 46 |
# File 'lib/carrierwave/storage/postgresql_lo.rb', line 39 def file_length @uploader.model.transaction do lo = connection.lo_open(identifier) size = connection.lo_lseek(lo, 0, 2) connection.lo_close(lo) size end end |
#identifier ⇒ Object
54 55 56 |
# File 'lib/carrierwave/storage/postgresql_lo.rb', line 54 def identifier @oid ||= @uploader.identifier end |
#original_filename ⇒ Object
58 59 60 |
# File 'lib/carrierwave/storage/postgresql_lo.rb', line 58 def original_filename identifier.to_s end |
#read ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/carrierwave/storage/postgresql_lo.rb', line 14 def read @uploader.model.transaction do lo = connection.lo_open(identifier) content = connection.lo_read(lo, file_length) connection.lo_close(lo) content end end |
#url ⇒ Object
10 11 12 |
# File 'lib/carrierwave/storage/postgresql_lo.rb', line 10 def url "/#{@uploader.model.class.name.downcase}_#{@uploader.mounted_as.downcase}/#{identifier}" end |
#write(file) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/carrierwave/storage/postgresql_lo.rb', line 23 def write(file) @uploader.model.transaction do lo = connection.lo_open(identifier, ::PG::INV_WRITE) size = connection.lo_write(lo, file.read) connection.lo_close(lo) size end end |