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.



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

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

Instance Attribute Details

#columnObject (readonly)

:nodoc:



284
285
286
# File 'lib/carrierwave/mount.rb', line 284

def column
  @column
end

#integrity_errorObject (readonly)

:nodoc:



284
285
286
# File 'lib/carrierwave/mount.rb', line 284

def integrity_error
  @integrity_error
end

#processing_errorObject (readonly)

:nodoc:



284
285
286
# File 'lib/carrierwave/mount.rb', line 284

def processing_error
  @processing_error
end

#recordObject (readonly)

:nodoc:



284
285
286
# File 'lib/carrierwave/mount.rb', line 284

def record
  @record
end

#remote_urlObject

:nodoc:



284
285
286
# File 'lib/carrierwave/mount.rb', line 284

def remote_url
  @remote_url
end

#removeObject

Returns the value of attribute remove.



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

def remove
  @remove
end

#uploader_optionsObject

Returns the value of attribute uploader_options.



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

def uploader_options
  @uploader_options
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


354
355
356
# File 'lib/carrierwave/mount.rb', line 354

def blank?
  uploader.blank?
end

#cache(new_file) ⇒ Object



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

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



326
327
328
# File 'lib/carrierwave/mount.rb', line 326

def cache_name
  uploader.cache_name
end

#cache_name=(cache_name) ⇒ Object



330
331
332
333
# File 'lib/carrierwave/mount.rb', line 330

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

#identifierObject



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

def identifier
  record.read_uploader(serialization_column)
end

#remove!Object



362
363
364
# File 'lib/carrierwave/mount.rb', line 362

def remove!
  uploader.remove!
end

#remove?Boolean

Returns:

  • (Boolean)


358
359
360
# File 'lib/carrierwave/mount.rb', line 358

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

#serialization_columnObject



366
367
368
# File 'lib/carrierwave/mount.rb', line 366

def serialization_column
  option(:mount_on) || column
end

#store!Object



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

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

#uploaderObject



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

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



350
351
352
# File 'lib/carrierwave/mount.rb', line 350

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

#write_identifierObject



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

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