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.



222
223
224
225
226
# File 'lib/carrierwave/mount.rb', line 222

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

Instance Attribute Details

#columnObject (readonly)

:nodoc:



218
219
220
# File 'lib/carrierwave/mount.rb', line 218

def column
  @column
end

#integrity_errorObject

Returns the value of attribute integrity_error.



220
221
222
# File 'lib/carrierwave/mount.rb', line 220

def integrity_error
  @integrity_error
end

#optionsObject (readonly)

:nodoc:



218
219
220
# File 'lib/carrierwave/mount.rb', line 218

def options
  @options
end

#processing_errorObject

Returns the value of attribute processing_error.



220
221
222
# File 'lib/carrierwave/mount.rb', line 220

def processing_error
  @processing_error
end

#recordObject (readonly)

:nodoc:



218
219
220
# File 'lib/carrierwave/mount.rb', line 218

def record
  @record
end

#removeObject

Returns the value of attribute remove.



220
221
222
# File 'lib/carrierwave/mount.rb', line 220

def remove
  @remove
end

#uploaderObject

Returns the value of attribute uploader.



220
221
222
# File 'lib/carrierwave/mount.rb', line 220

def uploader
  @uploader
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


274
275
276
# File 'lib/carrierwave/mount.rb', line 274

def blank?
  uploader.blank?
end

#cache(new_file) ⇒ Object



237
238
239
240
241
242
243
244
245
246
247
# File 'lib/carrierwave/mount.rb', line 237

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

#cache_nameObject



249
250
251
# File 'lib/carrierwave/mount.rb', line 249

def cache_name
  uploader.cache_name
end

#cache_name=(cache_name) ⇒ Object



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

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

#remove!Object



282
283
284
# File 'lib/carrierwave/mount.rb', line 282

def remove!
  uploader.remove!
end

#remove?Boolean

Returns:

  • (Boolean)


278
279
280
# File 'lib/carrierwave/mount.rb', line 278

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

#store!Object



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

def store!
  unless uploader.blank?
    if remove?
      uploader.remove!
      record.write_uploader(serialization_column, '')
    else
      uploader.store!
      record.write_uploader(serialization_column, uploader.identifier)
    end
  end
end

#url(*args) ⇒ Object



270
271
272
# File 'lib/carrierwave/mount.rb', line 270

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