Class: CarrierWave::Mount::Mounter

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Memoizable
Defined in:
lib/carrierwave/mount.rb

Overview

this is an internal class, used by CarrierWave::Mount so that we don’t pollute the model with a lot of methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, column, options = {}) ⇒ Mounter

Returns a new instance of Mounter.



289
290
291
292
293
# File 'lib/carrierwave/mount.rb', line 289

def initialize(record, column, options={})
  @record = record
  @column = column
  @options = record.class.uploader_options[column]
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



286
287
288
# File 'lib/carrierwave/mount.rb', line 286

def column
  @column
end

#integrity_errorObject (readonly)

Returns the value of attribute integrity_error.



286
287
288
# File 'lib/carrierwave/mount.rb', line 286

def integrity_error
  @integrity_error
end

#processing_errorObject (readonly)

Returns the value of attribute processing_error.



286
287
288
# File 'lib/carrierwave/mount.rb', line 286

def processing_error
  @processing_error
end

#recordObject (readonly)

Returns the value of attribute record.



286
287
288
# File 'lib/carrierwave/mount.rb', line 286

def record
  @record
end

#remote_urlObject

Returns the value of attribute remote_url.



286
287
288
# File 'lib/carrierwave/mount.rb', line 286

def remote_url
  @remote_url
end

#removeObject

Returns the value of attribute remove.



287
288
289
# File 'lib/carrierwave/mount.rb', line 287

def remove
  @remove
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


356
357
358
# File 'lib/carrierwave/mount.rb', line 356

def blank?
  uploader.blank?
end

#cache(new_file) ⇒ Object



316
317
318
319
320
321
322
323
324
325
326
# File 'lib/carrierwave/mount.rb', line 316

def cache(new_file)
  uploader.cache!(new_file)
  @integrity_error = nil
  @processing_error = nil
rescue CarrierWave::IntegrityError => e
  @integrity_error = e
  raise e unless option(:ignore_integrity_errors)
rescue CarrierWave::ProcessingError => e
  @processing_error = e
  raise e unless option(:ignore_processing_errors)
end

#cache_nameObject



328
329
330
# File 'lib/carrierwave/mount.rb', line 328

def cache_name
  uploader.cache_name
end

#cache_name=(cache_name) ⇒ Object



332
333
334
335
# File 'lib/carrierwave/mount.rb', line 332

def cache_name=(cache_name)
  uploader.retrieve_from_cache!(cache_name) unless uploader.cached?
rescue CarrierWave::InvalidParameter
end

#identifierObject



303
304
305
# File 'lib/carrierwave/mount.rb', line 303

def identifier
  record.read_uploader(serialization_column)
end

#remove!Object



364
365
366
# File 'lib/carrierwave/mount.rb', line 364

def remove!
  uploader.remove!
end

#remove?Boolean

Returns:

  • (Boolean)


360
361
362
# File 'lib/carrierwave/mount.rb', line 360

def remove?
  !remove.blank? and remove !~ /\A0|false$\z/
end

#serialization_columnObject



368
369
370
# File 'lib/carrierwave/mount.rb', line 368

def serialization_column
  option(:mount_on) || column
end

#store!Object



342
343
344
345
346
347
348
349
350
# File 'lib/carrierwave/mount.rb', line 342

def store!
  unless uploader.blank?
    if remove?
      uploader.remove!
    else
      uploader.store!
    end
  end
end

#uploaderObject



307
308
309
310
311
312
313
314
# File 'lib/carrierwave/mount.rb', line 307

def uploader
  @uploader ||= record.class.uploaders[column].new(record, column)

  if @uploader.blank? and not identifier.blank?
    @uploader.retrieve_from_store!(identifier)
  end
  return @uploader
end

#url(*args) ⇒ Object



352
353
354
# File 'lib/carrierwave/mount.rb', line 352

def url(*args)
  uploader.url(*args)
end

#write_identifierObject



295
296
297
298
299
300
301
# File 'lib/carrierwave/mount.rb', line 295

def write_identifier
  if remove?
    record.write_uploader(serialization_column, '')
  elsif not uploader.identifier.blank?
    record.write_uploader(serialization_column, uploader.identifier)
  end
end