Class: CarrierWave::Mount::Mounter
- Inherits:
-
Object
- Object
- CarrierWave::Mount::Mounter
- 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
-
#column ⇒ Object
readonly
:nodoc:.
-
#download_error ⇒ Object
readonly
:nodoc:.
-
#integrity_error ⇒ Object
readonly
:nodoc:.
-
#processing_error ⇒ Object
readonly
:nodoc:.
-
#record ⇒ Object
readonly
:nodoc:.
-
#remote_url ⇒ Object
:nodoc:.
-
#remove ⇒ Object
Returns the value of attribute remove.
-
#uploader_options ⇒ Object
Returns the value of attribute uploader_options.
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #cache(new_file) ⇒ Object
- #cache_name ⇒ Object
- #cache_name=(cache_name) ⇒ Object
- #identifier ⇒ Object
-
#initialize(record, column, options = {}) ⇒ Mounter
constructor
A new instance of Mounter.
- #remove! ⇒ Object
- #remove? ⇒ Boolean
- #serialization_column ⇒ Object
- #store! ⇒ Object
- #uploader ⇒ Object
- #url(*args) ⇒ Object
- #write_identifier ⇒ Object
Constructor Details
#initialize(record, column, options = {}) ⇒ Mounter
Returns a new instance of Mounter.
297 298 299 300 301 |
# File 'lib/carrierwave/mount.rb', line 297 def initialize(record, column, ={}) @record = record @column = column @options = record.class.[column] end |
Instance Attribute Details
#column ⇒ Object (readonly)
:nodoc:
294 295 296 |
# File 'lib/carrierwave/mount.rb', line 294 def column @column end |
#download_error ⇒ Object (readonly)
:nodoc:
294 295 296 |
# File 'lib/carrierwave/mount.rb', line 294 def download_error @download_error end |
#integrity_error ⇒ Object (readonly)
:nodoc:
294 295 296 |
# File 'lib/carrierwave/mount.rb', line 294 def integrity_error @integrity_error end |
#processing_error ⇒ Object (readonly)
:nodoc:
294 295 296 |
# File 'lib/carrierwave/mount.rb', line 294 def processing_error @processing_error end |
#record ⇒ Object (readonly)
:nodoc:
294 295 296 |
# File 'lib/carrierwave/mount.rb', line 294 def record @record end |
#remote_url ⇒ Object
:nodoc:
294 295 296 |
# File 'lib/carrierwave/mount.rb', line 294 def remote_url @remote_url end |
#remove ⇒ Object
Returns the value of attribute remove.
295 296 297 |
# File 'lib/carrierwave/mount.rb', line 295 def remove @remove end |
#uploader_options ⇒ Object
Returns the value of attribute uploader_options.
396 397 398 |
# File 'lib/carrierwave/mount.rb', line 396 def @uploader_options end |
Instance Method Details
#blank? ⇒ Boolean
380 381 382 |
# File 'lib/carrierwave/mount.rb', line 380 def blank? uploader.blank? end |
#cache(new_file) ⇒ Object
326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/carrierwave/mount.rb', line 326 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_name ⇒ Object
338 339 340 |
# File 'lib/carrierwave/mount.rb', line 338 def cache_name uploader.cache_name end |
#cache_name=(cache_name) ⇒ Object
342 343 344 345 |
# File 'lib/carrierwave/mount.rb', line 342 def cache_name=(cache_name) uploader.retrieve_from_cache!(cache_name) unless uploader.cached? rescue CarrierWave::InvalidParameter end |
#identifier ⇒ Object
313 314 315 |
# File 'lib/carrierwave/mount.rb', line 313 def identifier record.read_uploader(serialization_column) end |
#remove! ⇒ Object
388 389 390 |
# File 'lib/carrierwave/mount.rb', line 388 def remove! uploader.remove! end |
#remove? ⇒ Boolean
384 385 386 |
# File 'lib/carrierwave/mount.rb', line 384 def remove? !remove.blank? and remove !~ /\A0|false$\z/ end |
#serialization_column ⇒ Object
392 393 394 |
# File 'lib/carrierwave/mount.rb', line 392 def serialization_column option(:mount_on) || column end |
#store! ⇒ Object
366 367 368 369 370 371 372 373 374 |
# File 'lib/carrierwave/mount.rb', line 366 def store! unless uploader.blank? if remove? uploader.remove! else uploader.store! end end end |
#uploader ⇒ Object
317 318 319 320 321 322 323 324 |
# File 'lib/carrierwave/mount.rb', line 317 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
376 377 378 |
# File 'lib/carrierwave/mount.rb', line 376 def url(*args) uploader.url(*args) end |
#write_identifier ⇒ Object
303 304 305 306 307 308 309 310 311 |
# File 'lib/carrierwave/mount.rb', line 303 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 |