I am trying to debug some Carrierwave nonsense. This is what I understand so far:
I think this code in my carrierwave.rb initializer gets run after the app/uploader files are loaded. The reason why I think that is because my fixture files get uploaded to these directories defined here:
This is my carrierwave.rb initializer:
if Rails.env.test?
ZipCodeCsvUploader
StoryMainImageUploader
# use different dirs when testing
CarrierWave::Uploader::Base.descendants.each do |klass|
next if klass.anonymous?
klass.class_eval do
def cache_dir
"#{Rails.root}/spec/support/uploads/tmp/#{object_id}"
end
def store_dir
"#{Rails.root}/spec/support/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
# "#{Rails.root}/support/images/#{model.class.to_s.underscore}/#{mounted_as}/#{object_id}"
end
end
end
end
The store_dir and the cache_dir seem to trump this app/uploaded file:
# encoding: utf-8
require 'carrierwave/processing/mime_types'
class StoryMainImageUploader < CarrierWave::Uploader::Base
include CarrierWaveDirect::Uploader
include CarrierWave::RMagick
include CarrierWave::MimeTypes
include S3DirectUploader
process :set_content_type
def store_dir
"stories/#{model.id}/main_images"
end
def cache_dir
"#{Rails.root}/support/uploads/tmp/#{object_id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
version :medium do
process :resize_to_limit => [800, 800]
end
version :thumb do
process :resize_to_limit => [200, 200]
end
end
None of the uploads will hit these files.
So my questions:
-
Do the app files get loaded in a Rails app startup before the initializers?
-
What do the lines:
ZipCodeCsvUploader StoryMainImageUploader
do? How do we have access to these class names unless the classes were loaded first? Even if we do, what does calling these class names do?
Aucun commentaire:
Enregistrer un commentaire