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

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

Returns a new instance of Mounter.



292
293
294
295
296
# File 'lib/carrierwave/mount.rb', line 292

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

Instance Attribute Details

#columnObject (readonly)

:nodoc:



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

def column
  @column
end

#download_errorObject (readonly)

:nodoc:



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

def download_error
  @download_error
end

#integrity_errorObject (readonly)

:nodoc:



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

def integrity_error
  @integrity_error
end

#processing_errorObject (readonly)

:nodoc:



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

def processing_error
  @processing_error
end

#recordObject (readonly)

:nodoc:



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

def record
  @record
end

#remote_urlObject

:nodoc:



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

def remote_url
  @remote_url
end

#removeObject

Returns the value of attribute remove.



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

def remove
  @remove
end

#uploader_optionsObject

Returns the value of attribute uploader_options.



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

def uploader_options
  @uploader_options
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


375
376
377
# File 'lib/carrierwave/mount.rb', line 375

def blank?
  uploader.blank?
end

#cache(new_file) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
# File 'lib/carrierwave/mount.rb', line 321

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



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

def cache_name
  uploader.cache_name
end

#cache_name=(cache_name) ⇒ Object



337
338
339
340
# File 'lib/carrierwave/mount.rb', line 337

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

#identifierObject



308
309
310
# File 'lib/carrierwave/mount.rb', line 308

def identifier
  record.read_uploader(serialization_column)
end

#remove!Object



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

def remove!
  uploader.remove!
end

#remove?Boolean

Returns:

  • (Boolean)


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

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

#serialization_columnObject



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

def serialization_column
  option(:mount_on) || column
end

#store!Object



361
362
363
364
365
366
367
368
369
# File 'lib/carrierwave/mount.rb', line 361

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

#uploaderObject



312
313
314
315
316
317
318
319
# File 'lib/carrierwave/mount.rb', line 312

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



371
372
373
# File 'lib/carrierwave/mount.rb', line 371

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

#write_identifierObject



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

def write_identifier
  return if record.frozen?

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