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:.
-
#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.
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #cache(new_file) ⇒ Object
- #cache_name ⇒ Object
- #cache_name=(cache_name) ⇒ Object
- #check_stale_record! ⇒ Object
- #identifier ⇒ Object
-
#initialize(record, column, options = {}) ⇒ Mounter
constructor
A new instance of Mounter.
- #remove! ⇒ Object
- #remove? ⇒ Boolean
- #rename! ⇒ Object
- #store! ⇒ Object
- #uploader ⇒ Object
- #url(*args) ⇒ Object
- #write_identifier ⇒ Object
Constructor Details
#initialize(record, column, options = {}) ⇒ Mounter
Returns a new instance of Mounter.
273 274 275 276 277 |
# File 'lib/carrierwave/mount.rb', line 273 def initialize(record, column, ={}) @record = record @column = column @options = record.class.[column] end |
Instance Attribute Details
#column ⇒ Object (readonly)
:nodoc:
270 271 272 |
# File 'lib/carrierwave/mount.rb', line 270 def column @column end |
#integrity_error ⇒ Object (readonly)
:nodoc:
270 271 272 |
# File 'lib/carrierwave/mount.rb', line 270 def integrity_error @integrity_error end |
#processing_error ⇒ Object (readonly)
:nodoc:
270 271 272 |
# File 'lib/carrierwave/mount.rb', line 270 def processing_error @processing_error end |
#record ⇒ Object (readonly)
:nodoc:
270 271 272 |
# File 'lib/carrierwave/mount.rb', line 270 def record @record end |
#remote_url ⇒ Object
:nodoc:
270 271 272 |
# File 'lib/carrierwave/mount.rb', line 270 def remote_url @remote_url end |
#remove ⇒ Object
Returns the value of attribute remove.
271 272 273 |
# File 'lib/carrierwave/mount.rb', line 271 def remove @remove end |
Instance Method Details
#blank? ⇒ Boolean
342 343 344 |
# File 'lib/carrierwave/mount.rb', line 342 def blank? uploader.blank? end |
#cache(new_file) ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/carrierwave/mount.rb', line 300 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
312 313 314 |
# File 'lib/carrierwave/mount.rb', line 312 def cache_name uploader.cache_name end |
#cache_name=(cache_name) ⇒ Object
316 317 318 319 |
# File 'lib/carrierwave/mount.rb', line 316 def cache_name=(cache_name) uploader.retrieve_from_cache!(cache_name) unless uploader.cached? rescue CarrierWave::InvalidParameter end |
#check_stale_record! ⇒ Object
358 359 360 361 |
# File 'lib/carrierwave/mount.rb', line 358 def check_stale_record! uploader.send(:check_stale_model!) true end |
#identifier ⇒ Object
287 288 289 |
# File 'lib/carrierwave/mount.rb', line 287 def identifier record.read_uploader(serialization_column) end |
#remove! ⇒ Object
350 351 352 |
# File 'lib/carrierwave/mount.rb', line 350 def remove! uploader.remove! end |
#remove? ⇒ Boolean
346 347 348 |
# File 'lib/carrierwave/mount.rb', line 346 def remove? !remove.blank? and remove !~ /\A0|false$\z/ end |
#rename! ⇒ Object
354 355 356 |
# File 'lib/carrierwave/mount.rb', line 354 def rename! uploader.rename! end |
#store! ⇒ Object
328 329 330 331 332 333 334 335 336 |
# File 'lib/carrierwave/mount.rb', line 328 def store! unless uploader.blank? if remove? uploader.remove! else uploader.store! end end end |
#uploader ⇒ Object
291 292 293 294 295 296 297 298 |
# File 'lib/carrierwave/mount.rb', line 291 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
338 339 340 |
# File 'lib/carrierwave/mount.rb', line 338 def url(*args) uploader.url(*args) end |
#write_identifier ⇒ Object
279 280 281 282 283 284 285 |
# File 'lib/carrierwave/mount.rb', line 279 def write_identifier if remove? record.write_uploader(serialization_column, '') elsif not uploader.identifier.blank? record.write_uploader(serialization_column, uploader.identifier) end end |