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.



254
255
256
257
258
# File 'lib/carrierwave/mount.rb', line 254

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

Instance Attribute Details

#columnObject (readonly)

:nodoc:



251
252
253
# File 'lib/carrierwave/mount.rb', line 251

def column
  @column
end

#integrity_errorObject (readonly)

:nodoc:



251
252
253
# File 'lib/carrierwave/mount.rb', line 251

def integrity_error
  @integrity_error
end

#processing_errorObject (readonly)

:nodoc:



251
252
253
# File 'lib/carrierwave/mount.rb', line 251

def processing_error
  @processing_error
end

#recordObject (readonly)

:nodoc:



251
252
253
# File 'lib/carrierwave/mount.rb', line 251

def record
  @record
end

#removeObject

Returns the value of attribute remove.



252
253
254
# File 'lib/carrierwave/mount.rb', line 252

def remove
  @remove
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


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

def blank?
  uploader.blank?
end

#cache(new_file) ⇒ Object



281
282
283
284
285
286
287
288
289
290
291
# File 'lib/carrierwave/mount.rb', line 281

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



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

def cache_name
  uploader.cache_name
end

#cache_name=(cache_name) ⇒ Object



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

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

#identifierObject



268
269
270
# File 'lib/carrierwave/mount.rb', line 268

def identifier
  record.read_uploader(serialization_column)
end

#remove!Object



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

def remove!
  uploader.remove!
end

#remove?Boolean

Returns:

  • (Boolean)


320
321
322
# File 'lib/carrierwave/mount.rb', line 320

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

#store!Object



302
303
304
305
306
307
308
309
310
# File 'lib/carrierwave/mount.rb', line 302

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

#uploaderObject



272
273
274
275
276
277
278
279
# File 'lib/carrierwave/mount.rb', line 272

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



312
313
314
# File 'lib/carrierwave/mount.rb', line 312

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

#write_identifierObject



260
261
262
263
264
265
266
# File 'lib/carrierwave/mount.rb', line 260

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