Class: CarrierWave::Mount::Mounter

Inherits:
Object
  • Object
show all
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

- (Mounter) initialize(record, column, options = {})



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

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

Instance Attribute Details

- (Object) column (readonly)

:nodoc:



298
299
300
# File 'lib/carrierwave/mount.rb', line 298

def column
  @column
end

- (Object) download_error (readonly)

:nodoc:



298
299
300
# File 'lib/carrierwave/mount.rb', line 298

def download_error
  @download_error
end

- (Object) integrity_error (readonly)

:nodoc:



298
299
300
# File 'lib/carrierwave/mount.rb', line 298

def integrity_error
  @integrity_error
end

- (Object) processing_error (readonly)

:nodoc:



298
299
300
# File 'lib/carrierwave/mount.rb', line 298

def processing_error
  @processing_error
end

- (Object) record (readonly)

:nodoc:



298
299
300
# File 'lib/carrierwave/mount.rb', line 298

def record
  @record
end

- (Object) remote_url

:nodoc:



298
299
300
# File 'lib/carrierwave/mount.rb', line 298

def remote_url
  @remote_url
end

- (Object) remove

Returns the value of attribute remove



299
300
301
# File 'lib/carrierwave/mount.rb', line 299

def remove
  @remove
end

- (Object) uploader_options

Returns the value of attribute uploader_options



399
400
401
# File 'lib/carrierwave/mount.rb', line 399

def uploader_options
  @uploader_options
end

Instance Method Details

- (Boolean) blank?



383
384
385
# File 'lib/carrierwave/mount.rb', line 383

def blank?
  uploader.blank?
end

- (Object) cache(new_file)



328
329
330
331
332
333
334
335
336
337
338
# File 'lib/carrierwave/mount.rb', line 328

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

- (Object) cache_name



340
341
342
# File 'lib/carrierwave/mount.rb', line 340

def cache_name
  uploader.cache_name
end

- (Object) cache_name=(cache_name)



344
345
346
347
# File 'lib/carrierwave/mount.rb', line 344

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

- (Object) identifier



317
318
319
# File 'lib/carrierwave/mount.rb', line 317

def identifier
  record.read_uploader(serialization_column)
end

- (Object) remove!



391
392
393
# File 'lib/carrierwave/mount.rb', line 391

def remove!
  uploader.remove!
end

- (Boolean) remove?



387
388
389
# File 'lib/carrierwave/mount.rb', line 387

def remove?
  remove.present? && remove !~ /\A0|false$\z/
end

- (Object) serialization_column



395
396
397
# File 'lib/carrierwave/mount.rb', line 395

def serialization_column
  option(:mount_on) || column
end

- (Object) store!



369
370
371
372
373
374
375
376
377
# File 'lib/carrierwave/mount.rb', line 369

def store!
  return if uploader.blank?

  if remove?
    uploader.remove!
  else
    uploader.store!
  end
end

- (Object) uploader



321
322
323
324
325
326
# File 'lib/carrierwave/mount.rb', line 321

def uploader
  @uploader ||= record.class.uploaders[column].new(record, column)
  @uploader.retrieve_from_store!(identifier) if @uploader.blank? && identifier.present?

  @uploader
end

- (Object) url(*args)



379
380
381
# File 'lib/carrierwave/mount.rb', line 379

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

- (Object) write_identifier



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

def write_identifier
  return if record.frozen?

  if remove?
    record.write_uploader(serialization_column, nil)
  elsif uploader.identifier.present?
    record.write_uploader(serialization_column, uploader.identifier)
  end
end