-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
carrierwave.rb
103 lines (86 loc) · 2.84 KB
/
carrierwave.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require 'fileutils'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/try'
require 'active_support/core_ext/class/attribute'
require 'active_support/concern'
module CarrierWave
class << self
attr_accessor :root, :base_path
attr_writer :tmp_path
def configure(&block)
CarrierWave::Uploader::Base.configure(&block)
end
def clean_cached_files!(seconds=60*60*24)
CarrierWave::Uploader::Base.clean_cached_files!(seconds)
end
def tmp_path
@tmp_path ||= File.expand_path(File.join('..', 'tmp'), root)
end
end
end
if defined?(Merb)
CarrierWave.root = Merb.dir_for(:public)
Merb::BootLoader.before_app_loads do
# Setup path for uploaders and load all of them before classes are loaded
Merb.push_path(:uploaders, Merb.root / 'app' / 'uploaders', '*.rb')
Dir.glob(File.join(Merb.load_paths[:uploaders])).each {|f| require f }
end
elsif defined?(Jets)
module CarrierWave
class Turbine < Jets::Turbine
initializer "carrierwave.setup_paths" do |app|
CarrierWave.root = Jets.root.to_s
CarrierWave.tmp_path = "/tmp/carrierwave"
CarrierWave.configure do |config|
config.cache_dir = "/tmp/carrierwave/uploads/tmp"
end
end
initializer "carrierwave.active_record" do
ActiveSupport.on_load :active_record do
require 'carrierwave/orm/activerecord'
end
end
end
end
elsif defined?(Rails)
module CarrierWave
class Railtie < Rails::Railtie
initializer "carrierwave.setup_paths" do |app|
CarrierWave.root = Rails.root.join(Rails.public_path).to_s
CarrierWave.base_path = ENV['RAILS_RELATIVE_URL_ROOT']
available_locales = Array(app.config.i18n.available_locales || [])
if available_locales.blank? || available_locales.include?(:en)
I18n.load_path.prepend(File.join(File.dirname(__FILE__), 'carrierwave', 'locale', "en.yml"))
end
end
initializer "carrierwave.active_record" do
ActiveSupport.on_load :active_record do
require 'carrierwave/orm/activerecord'
end
end
end
end
elsif defined?(Sinatra)
if defined?(Padrino) && defined?(PADRINO_ROOT)
CarrierWave.root = File.join(PADRINO_ROOT, "public")
else
CarrierWave.root = if Sinatra::Application.respond_to?(:public_folder)
# Sinatra >= 1.3
Sinatra::Application.public_folder
else
# Sinatra < 1.3
Sinatra::Application.public
end
end
end
require "carrierwave/utilities"
require "carrierwave/error"
require "carrierwave/sanitized_file"
require "carrierwave/mounter"
require "carrierwave/mount"
require "carrierwave/processing"
require "carrierwave/version"
require "carrierwave/storage"
require "carrierwave/uploader"
require "carrierwave/compatibility/paperclip"
require "carrierwave/test/matchers"