Class: CarrierWave::Mount::Mounter
- Inherits:
-
Object
- Object
- CarrierWave::Mount::Mounter
- Extended by:
- ActiveSupport::Memoizable
- 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
Returns the value of attribute column.
-
#integrity_error ⇒ Object
readonly
Returns the value of attribute integrity_error.
-
#processing_error ⇒ Object
readonly
Returns the value of attribute processing_error.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#remote_url ⇒ Object
Returns the value of attribute remote_url.
-
#remove ⇒ Object
Returns the value of attribute remove.
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.
291 292 293 294 295 |
# File 'lib/carrierwave/mount.rb', line 291 def initialize(record, column, ={}) @record = record @column = column @options = record.class.[column] end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
288 289 290 |
# File 'lib/carrierwave/mount.rb', line 288 def column @column end |
#integrity_error ⇒ Object (readonly)
Returns the value of attribute integrity_error.
288 289 290 |
# File 'lib/carrierwave/mount.rb', line 288 def integrity_error @integrity_error end |
#processing_error ⇒ Object (readonly)
Returns the value of attribute processing_error.
288 289 290 |
# File 'lib/carrierwave/mount.rb', line 288 def processing_error @processing_error end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
288 289 290 |
# File 'lib/carrierwave/mount.rb', line 288 def record @record end |
#remote_url ⇒ Object
Returns the value of attribute remote_url.
288 289 290 |
# File 'lib/carrierwave/mount.rb', line 288 def remote_url @remote_url end |
#remove ⇒ Object
Returns the value of attribute remove.
289 290 291 |
# File 'lib/carrierwave/mount.rb', line 289 def remove @remove end |
Instance Method Details
#blank? ⇒ Boolean
360 361 362 |
# File 'lib/carrierwave/mount.rb', line 360 def blank? uploader.blank? end |
#cache(new_file) ⇒ Object
318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/carrierwave/mount.rb', line 318 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
330 331 332 |
# File 'lib/carrierwave/mount.rb', line 330 def cache_name uploader.cache_name end |
#cache_name=(cache_name) ⇒ Object
334 335 336 337 |
# File 'lib/carrierwave/mount.rb', line 334 def cache_name=(cache_name) uploader.retrieve_from_cache!(cache_name) unless uploader.cached? rescue CarrierWave::InvalidParameter end |
#identifier ⇒ Object
305 306 307 |
# File 'lib/carrierwave/mount.rb', line 305 def identifier record.read_uploader(serialization_column) end |
#remove! ⇒ Object
368 369 370 |
# File 'lib/carrierwave/mount.rb', line 368 def remove! uploader.remove! end |
#remove? ⇒ Boolean
364 365 366 |
# File 'lib/carrierwave/mount.rb', line 364 def remove? !remove.blank? and remove !~ /\A0|false$\z/ end |
#serialization_column ⇒ Object
372 373 374 |
# File 'lib/carrierwave/mount.rb', line 372 def serialization_column option(:mount_on) || column end |
#store! ⇒ Object
346 347 348 349 350 351 352 353 354 |
# File 'lib/carrierwave/mount.rb', line 346 def store! unless uploader.blank? if remove? uploader.remove! else uploader.store! end end end |
#uploader ⇒ Object
309 310 311 312 313 314 315 316 |
# File 'lib/carrierwave/mount.rb', line 309 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
356 357 358 |
# File 'lib/carrierwave/mount.rb', line 356 def url(*args) uploader.url(*args) end |
#write_identifier ⇒ Object
297 298 299 300 301 302 303 |
# File 'lib/carrierwave/mount.rb', line 297 def write_identifier if remove? record.write_uploader(serialization_column, '') elsif not uploader.identifier.blank? record.write_uploader(serialization_column, uploader.identifier) end end |