mini-smart-pkg 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/carrierwave-3.1.3/README.md +1214 -0
  3. data/carrierwave-3.1.3/lib/carrierwave/compatibility/paperclip.rb +105 -0
  4. data/carrierwave-3.1.3/lib/carrierwave/downloader/base.rb +101 -0
  5. data/carrierwave-3.1.3/lib/carrierwave/downloader/remote_file.rb +68 -0
  6. data/carrierwave-3.1.3/lib/carrierwave/error.rb +8 -0
  7. data/carrierwave-3.1.3/lib/carrierwave/locale/en.yml +17 -0
  8. data/carrierwave-3.1.3/lib/carrierwave/mount.rb +446 -0
  9. data/carrierwave-3.1.3/lib/carrierwave/mounter.rb +257 -0
  10. data/carrierwave-3.1.3/lib/carrierwave/orm/activerecord.rb +68 -0
  11. data/carrierwave-3.1.3/lib/carrierwave/processing/mini_magick.rb +362 -0
  12. data/carrierwave-3.1.3/lib/carrierwave/processing/rmagick.rb +433 -0
  13. data/carrierwave-3.1.3/lib/carrierwave/processing/vips.rb +315 -0
  14. data/carrierwave-3.1.3/lib/carrierwave/processing.rb +3 -0
  15. data/carrierwave-3.1.3/lib/carrierwave/sanitized_file.rb +361 -0
  16. data/carrierwave-3.1.3/lib/carrierwave/storage/abstract.rb +43 -0
  17. data/carrierwave-3.1.3/lib/carrierwave/storage/file.rb +124 -0
  18. data/carrierwave-3.1.3/lib/carrierwave/storage/fog.rb +560 -0
  19. data/carrierwave-3.1.3/lib/carrierwave/storage.rb +3 -0
  20. data/carrierwave-3.1.3/lib/carrierwave/test/matchers.rb +398 -0
  21. data/carrierwave-3.1.3/lib/carrierwave/uploader/cache.rb +223 -0
  22. data/carrierwave-3.1.3/lib/carrierwave/uploader/callbacks.rb +33 -0
  23. data/carrierwave-3.1.3/lib/carrierwave/uploader/configuration.rb +229 -0
  24. data/carrierwave-3.1.3/lib/carrierwave/uploader/content_type_allowlist.rb +62 -0
  25. data/carrierwave-3.1.3/lib/carrierwave/uploader/content_type_denylist.rb +65 -0
  26. data/carrierwave-3.1.3/lib/carrierwave/uploader/default_url.rb +17 -0
  27. data/carrierwave-3.1.3/lib/carrierwave/uploader/dimension.rb +66 -0
  28. data/carrierwave-3.1.3/lib/carrierwave/uploader/download.rb +24 -0
  29. data/carrierwave-3.1.3/lib/carrierwave/uploader/extension_allowlist.rb +63 -0
  30. data/carrierwave-3.1.3/lib/carrierwave/uploader/extension_denylist.rb +64 -0
  31. data/carrierwave-3.1.3/lib/carrierwave/uploader/file_size.rb +43 -0
  32. data/carrierwave-3.1.3/lib/carrierwave/uploader/mountable.rb +44 -0
  33. data/carrierwave-3.1.3/lib/carrierwave/uploader/processing.rb +128 -0
  34. data/carrierwave-3.1.3/lib/carrierwave/uploader/proxy.rb +99 -0
  35. data/carrierwave-3.1.3/lib/carrierwave/uploader/remove.rb +21 -0
  36. data/carrierwave-3.1.3/lib/carrierwave/uploader/serialization.rb +28 -0
  37. data/carrierwave-3.1.3/lib/carrierwave/uploader/store.rb +168 -0
  38. data/carrierwave-3.1.3/lib/carrierwave/uploader/url.rb +44 -0
  39. data/carrierwave-3.1.3/lib/carrierwave/uploader/versions.rb +352 -0
  40. data/carrierwave-3.1.3/lib/carrierwave/uploader.rb +69 -0
  41. data/carrierwave-3.1.3/lib/carrierwave/utilities/file_name.rb +47 -0
  42. data/carrierwave-3.1.3/lib/carrierwave/utilities/uri.rb +26 -0
  43. data/carrierwave-3.1.3/lib/carrierwave/utilities.rb +7 -0
  44. data/carrierwave-3.1.3/lib/carrierwave/validations/active_model.rb +76 -0
  45. data/carrierwave-3.1.3/lib/carrierwave/version.rb +3 -0
  46. data/carrierwave-3.1.3/lib/carrierwave.rb +108 -0
  47. data/carrierwave-3.1.3/lib/generators/templates/uploader.rb.erb +56 -0
  48. data/carrierwave-3.1.3/lib/generators/uploader_generator.rb +7 -0
  49. data/mini-smart-pkg.gemspec +12 -0
  50. metadata +89 -0
@@ -0,0 +1,352 @@
1
+ require "active_support/core_ext/object/deep_dup"
2
+
3
+ module CarrierWave
4
+ module Uploader
5
+ module Versions
6
+ class Builder
7
+ def initialize(name)
8
+ @name = name
9
+ @options = {}
10
+ @blocks = []
11
+ @klass = nil
12
+ end
13
+
14
+ def configure(options, &block)
15
+ @options.merge!(options)
16
+ @blocks << block if block
17
+ @klass = nil
18
+ end
19
+
20
+ def build(superclass)
21
+ return @klass if @klass
22
+ @klass = Class.new(superclass)
23
+ superclass.const_set("VersionUploader#{@name.to_s.camelize}", @klass)
24
+
25
+ @klass.version_names += [@name]
26
+ @klass.versions = {}
27
+ @klass.processors = []
28
+ @klass.version_options = @options
29
+ @klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
30
+ # Define the enable_processing method for versions so they get the
31
+ # value from the parent class unless explicitly overwritten
32
+ def self.enable_processing(value=nil)
33
+ self.enable_processing = value if value
34
+ if defined?(@enable_processing) && !@enable_processing.nil?
35
+ @enable_processing
36
+ else
37
+ superclass.enable_processing
38
+ end
39
+ end
40
+
41
+ # Regardless of what is set in the parent uploader, do not enforce the
42
+ # move_to_cache config option on versions because it moves the original
43
+ # file to the version's target file.
44
+ #
45
+ # If you want to enforce this setting on versions, override this method
46
+ # in each version:
47
+ #
48
+ # version :thumb do
49
+ # def move_to_cache
50
+ # true
51
+ # end
52
+ # end
53
+ #
54
+ def move_to_cache
55
+ false
56
+ end
57
+
58
+ # Need to rely on the parent version's identifier, as versions don't have its own one.
59
+ def identifier
60
+ parent_version.identifier
61
+ end
62
+ RUBY
63
+ @blocks.each { |block| @klass.class_eval(&block) }
64
+ @klass
65
+ end
66
+
67
+ def deep_dup
68
+ other = dup
69
+ other.instance_variable_set(:@blocks, @blocks.dup)
70
+ other
71
+ end
72
+
73
+ def method_missing(name, *args)
74
+ super
75
+ rescue NoMethodError => e
76
+ raise e.exception <<~ERROR
77
+ #{e.message}
78
+ If you're trying to configure a version, do it inside a block like `version(:thumb) { self.#{name} #{args.map(&:inspect).join(', ')} }`.
79
+ ERROR
80
+ end
81
+
82
+ def respond_to_missing?(*)
83
+ super
84
+ end
85
+ end
86
+
87
+ extend ActiveSupport::Concern
88
+
89
+ include CarrierWave::Uploader::Callbacks
90
+
91
+ included do
92
+ class_attribute :versions, :version_names, :version_options, :instance_reader => false, :instance_writer => false
93
+
94
+ self.versions = {}
95
+ self.version_names = []
96
+
97
+ attr_accessor :parent_version
98
+
99
+ after :cache, :cache_versions!
100
+ after :store, :store_versions!
101
+ after :remove, :remove_versions!
102
+ after :retrieve_from_cache, :retrieve_versions_from_cache!
103
+ after :retrieve_from_store, :retrieve_versions_from_store!
104
+
105
+ prepend Module.new {
106
+ def initialize(*)
107
+ super
108
+ @versions = nil
109
+ end
110
+ }
111
+ end
112
+
113
+ module ClassMethods
114
+
115
+ ##
116
+ # Adds a new version to this uploader
117
+ #
118
+ # === Parameters
119
+ #
120
+ # [name (#to_sym)] name of the version
121
+ # [options (Hash)] optional options hash
122
+ # [&block (Proc)] a block to eval on this version of the uploader
123
+ #
124
+ # === Examples
125
+ #
126
+ # class MyUploader < CarrierWave::Uploader::Base
127
+ #
128
+ # version :thumb do
129
+ # process :scale => [200, 200]
130
+ # end
131
+ #
132
+ # version :preview, :if => :image? do
133
+ # process :scale => [200, 200]
134
+ # end
135
+ #
136
+ # version :square, :unless => :invalid_image_type? do
137
+ # process :scale => [100, 100]
138
+ # end
139
+ #
140
+ # end
141
+ #
142
+ def version(name, options = {}, &block)
143
+ name = name.to_sym
144
+ versions[name] ||= Builder.new(name)
145
+ versions[name].configure(options, &block)
146
+
147
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
148
+ def #{name}
149
+ versions[:#{name}]
150
+ end
151
+ RUBY
152
+
153
+ versions[name]
154
+ end
155
+
156
+ private
157
+
158
+ def inherited(subclass)
159
+ # To prevent subclass version changes affecting superclass versions
160
+ subclass.versions = versions.deep_dup
161
+ super
162
+ end
163
+ end # ClassMethods
164
+
165
+ ##
166
+ # Returns a hash mapping the name of each version of the uploader to an instance of it
167
+ #
168
+ # === Returns
169
+ #
170
+ # [Hash{Symbol => CarrierWave::Uploader}] a list of uploader instances
171
+ #
172
+ def versions
173
+ return @versions if @versions
174
+ @versions = {}
175
+ self.class.versions.each do |name, version|
176
+ @versions[name] = version.build(self.class).new(model, mounted_as)
177
+ @versions[name].parent_version = self
178
+ end
179
+ @versions
180
+ end
181
+
182
+ ##
183
+ # === Returns
184
+ #
185
+ # [String] the name of this version of the uploader
186
+ #
187
+ def version_name
188
+ self.class.version_names.join('_').to_sym unless self.class.version_names.blank?
189
+ end
190
+
191
+ ##
192
+ #
193
+ # === Parameters
194
+ #
195
+ # [name (#to_sym)] name of the version
196
+ #
197
+ # === Returns
198
+ #
199
+ # [Boolean] True when the version satisfy its :if or :unless condition
200
+ #
201
+ def version_active?(name)
202
+ name = name.to_sym
203
+
204
+ return false unless versions.has_key?(name)
205
+
206
+ if_condition = versions[name].class.version_options[:if]
207
+ unless_condition = versions[name].class.version_options[:unless]
208
+
209
+ if if_condition
210
+ if if_condition.respond_to?(:call)
211
+ if_condition.call(self, :version => name, :file => file)
212
+ else
213
+ send(if_condition, file)
214
+ end
215
+ elsif unless_condition
216
+ if unless_condition.respond_to?(:call)
217
+ !unless_condition.call(self, :version => name, :file => file)
218
+ else
219
+ !send(unless_condition, file)
220
+ end
221
+ else
222
+ true
223
+ end
224
+ end
225
+ alias_method :version_exists?, :version_active?
226
+ CarrierWave.deprecator.deprecate_methods(self, version_exists?: :version_active?)
227
+
228
+ ##
229
+ # Copies the parent's cache_id when caching a version file.
230
+ # This behavior is not essential but it makes easier to understand
231
+ # that the cached files are generated by the single upload attempt.
232
+ #
233
+ def cache!(*args)
234
+ self.cache_id = parent_version.cache_id if parent_version
235
+
236
+ super
237
+ end
238
+
239
+ ##
240
+ # When given a version name as a parameter, will return the url for that version
241
+ # This also works with nested versions.
242
+ # When given a query hash as a parameter, will return the url with signature that contains query params
243
+ # Query hash only works with AWS (S3 storage).
244
+ #
245
+ # === Example
246
+ #
247
+ # my_uploader.url # => /path/to/my/uploader.gif
248
+ # my_uploader.url(:thumb) # => /path/to/my/thumb_uploader.gif
249
+ # my_uploader.url(:thumb, :small) # => /path/to/my/thumb_small_uploader.gif
250
+ # my_uploader.url(:query => {"response-content-disposition" => "attachment"})
251
+ # my_uploader.url(:version, :sub_version, :query => {"response-content-disposition" => "attachment"})
252
+ #
253
+ # === Parameters
254
+ #
255
+ # [*args (Symbol)] any number of versions
256
+ # OR/AND
257
+ # [Hash] query params
258
+ #
259
+ # === Returns
260
+ #
261
+ # [String] the location where this file is accessible via a url
262
+ #
263
+ def url(*args)
264
+ if (version = args.first) && version.respond_to?(:to_sym)
265
+ raise ArgumentError, "Version #{version} doesn't exist!" if versions[version.to_sym].nil?
266
+ # recursively proxy to version
267
+ versions[version.to_sym].url(*args[1..-1])
268
+ elsif args.first
269
+ super(args.first)
270
+ else
271
+ super
272
+ end
273
+ end
274
+
275
+ ##
276
+ # Recreate versions and reprocess them. This can be used to recreate
277
+ # versions if their parameters somehow have changed.
278
+ #
279
+ def recreate_versions!(*names)
280
+ # As well as specified versions, we need to reprocess versions
281
+ # that are the source of another version.
282
+
283
+ self.cache_id = CarrierWave.generate_cache_id
284
+ derived_versions.each_value do |v|
285
+ v.cache!(file) if names.empty? || !(v.descendant_version_names & names).empty?
286
+ end
287
+ active_versions.each do |name, v|
288
+ v.store! if names.empty? || names.include?(name)
289
+ end
290
+ ensure
291
+ @cache_id = nil
292
+ end
293
+
294
+ protected
295
+
296
+ def descendant_version_names
297
+ [version_name] + derived_versions.flat_map do |name, version|
298
+ version.descendant_version_names
299
+ end
300
+ end
301
+
302
+ def active_versions
303
+ versions.select do |name, uploader|
304
+ version_active?(name)
305
+ end
306
+ end
307
+
308
+ private
309
+
310
+ def derived_versions
311
+ active_versions.reject do |name, v|
312
+ v.class.version_options[:from_version]
313
+ end.merge(active_sibling_versions.select do |name, v|
314
+ v.class.version_options[:from_version] == self.class.version_names.last
315
+ end)
316
+ end
317
+
318
+ def active_sibling_versions
319
+ parent_version&.active_versions || {}
320
+ end
321
+
322
+ def full_filename(for_file)
323
+ [version_name, super(for_file)].compact.join('_')
324
+ end
325
+
326
+ def full_original_filename
327
+ [version_name, super].compact.join('_')
328
+ end
329
+
330
+ def cache_versions!(new_file)
331
+ derived_versions.each_value { |v| v.cache!(new_file) }
332
+ end
333
+
334
+ def store_versions!(new_file)
335
+ active_versions.each_value { |v| v.store!(new_file) }
336
+ end
337
+
338
+ def remove_versions!
339
+ versions.each_value { |v| v.remove! }
340
+ end
341
+
342
+ def retrieve_versions_from_cache!(cache_name)
343
+ active_versions.each_value { |v| v.retrieve_from_cache!(cache_name) }
344
+ end
345
+
346
+ def retrieve_versions_from_store!(identifier)
347
+ active_versions.each_value { |v| v.retrieve_from_store!(identifier) }
348
+ end
349
+
350
+ end # Versions
351
+ end # Uploader
352
+ end # CarrierWave
@@ -0,0 +1,69 @@
1
+ require "carrierwave/uploader/configuration"
2
+ require "carrierwave/uploader/callbacks"
3
+ require "carrierwave/uploader/proxy"
4
+ require "carrierwave/uploader/url"
5
+ require "carrierwave/uploader/mountable"
6
+ require "carrierwave/uploader/cache"
7
+ require "carrierwave/uploader/store"
8
+ require "carrierwave/uploader/download"
9
+ require "carrierwave/uploader/remove"
10
+ require "carrierwave/uploader/extension_allowlist"
11
+ require "carrierwave/uploader/extension_denylist"
12
+ require "carrierwave/uploader/content_type_allowlist"
13
+ require "carrierwave/uploader/content_type_denylist"
14
+ require "carrierwave/uploader/file_size"
15
+ require "carrierwave/uploader/dimension"
16
+ require "carrierwave/uploader/processing"
17
+ require "carrierwave/uploader/versions"
18
+ require "carrierwave/uploader/default_url"
19
+
20
+ require "carrierwave/uploader/serialization"
21
+
22
+ module CarrierWave
23
+
24
+ ##
25
+ # See CarrierWave::Uploader::Base
26
+ #
27
+ module Uploader
28
+
29
+ ##
30
+ # An uploader is a class that allows you to easily handle the caching and storage of
31
+ # uploaded files. Please refer to the README for configuration options.
32
+ #
33
+ # Once you have an uploader you can use it in isolation:
34
+ #
35
+ # my_uploader = MyUploader.new
36
+ # my_uploader.cache!(File.open(path_to_file))
37
+ # my_uploader.retrieve_from_store!('monkey.png')
38
+ #
39
+ # Alternatively, you can mount it on an ORM or other persistence layer, with
40
+ # +CarrierWave::Mount#mount_uploader+. There are extensions for activerecord and datamapper
41
+ # these are *very* simple (they are only a dozen lines of code), so adding your own should
42
+ # be trivial.
43
+ #
44
+ class Base
45
+ attr_reader :file
46
+
47
+ include CarrierWave::Uploader::Configuration
48
+ include CarrierWave::Uploader::Callbacks
49
+ include CarrierWave::Uploader::Proxy
50
+ include CarrierWave::Uploader::Url
51
+ include CarrierWave::Uploader::Mountable
52
+ include CarrierWave::Uploader::Cache
53
+ include CarrierWave::Uploader::Store
54
+ include CarrierWave::Uploader::Download
55
+ include CarrierWave::Uploader::Remove
56
+ include CarrierWave::Uploader::ExtensionAllowlist
57
+ include CarrierWave::Uploader::ExtensionDenylist
58
+ include CarrierWave::Uploader::ContentTypeAllowlist
59
+ include CarrierWave::Uploader::ContentTypeDenylist
60
+ include CarrierWave::Uploader::FileSize
61
+ include CarrierWave::Uploader::Dimension
62
+ include CarrierWave::Uploader::Processing
63
+ include CarrierWave::Uploader::Versions
64
+ include CarrierWave::Uploader::DefaultUrl
65
+ include CarrierWave::Uploader::Serialization
66
+ end # Base
67
+
68
+ end # Uploader
69
+ end # CarrierWave
@@ -0,0 +1,47 @@
1
+ module CarrierWave
2
+ module Utilities
3
+ module FileName
4
+
5
+ ##
6
+ # Returns the part of the filename before the extension. So if a file is called 'test.jpeg'
7
+ # this would return 'test'
8
+ #
9
+ # === Returns
10
+ #
11
+ # [String] the first part of the filename
12
+ #
13
+ def basename
14
+ split_extension(filename)[0] if filename
15
+ end
16
+
17
+ ##
18
+ # Returns the file extension
19
+ #
20
+ # === Returns
21
+ #
22
+ # [String] extension of file or "" if the file has no extension
23
+ #
24
+ def extension
25
+ split_extension(filename)[1] if filename
26
+ end
27
+
28
+ private
29
+
30
+ def split_extension(filename)
31
+ # regular expressions to try for identifying extensions
32
+ extension_matchers = [
33
+ /\A(.+)\.(tar\.([glx]?z|bz2))\z/, # matches "something.tar.gz"
34
+ /\A(.+)\.([^\.]+)\z/ # matches "something.jpg"
35
+ ]
36
+
37
+ extension_matchers.each do |regexp|
38
+ if filename =~ regexp
39
+ return $1, $2
40
+ end
41
+ end
42
+
43
+ [filename, ""] # In case we weren't able to split the extension
44
+ end
45
+ end # FileName
46
+ end # Utilities
47
+ end # CarrierWave
@@ -0,0 +1,26 @@
1
+ require 'uri'
2
+
3
+ module CarrierWave
4
+ module Utilities
5
+ module Uri
6
+ # based on Ruby < 2.0's URI.encode
7
+ PATH_SAFE = URI::RFC2396_REGEXP::PATTERN::UNRESERVED + '\/'
8
+ PATH_UNSAFE = Regexp.new("[^#{PATH_SAFE}]", false)
9
+ NON_ASCII = /[^[:ascii:]]/.freeze
10
+
11
+ private
12
+
13
+ def encode_path(path)
14
+ URI::DEFAULT_PARSER.escape(path, PATH_UNSAFE)
15
+ end
16
+
17
+ def encode_non_ascii(str)
18
+ URI::DEFAULT_PARSER.escape(str, NON_ASCII)
19
+ end
20
+
21
+ def decode_uri(str)
22
+ URI::DEFAULT_PARSER.unescape(str)
23
+ end
24
+ end # Uri
25
+ end # Utilities
26
+ end # CarrierWave
@@ -0,0 +1,7 @@
1
+ require 'carrierwave/utilities/uri'
2
+ require 'carrierwave/utilities/file_name'
3
+
4
+ module CarrierWave
5
+ module Utilities
6
+ end
7
+ end
@@ -0,0 +1,76 @@
1
+ require 'active_model/validator'
2
+ require 'active_support/concern'
3
+
4
+ module CarrierWave
5
+
6
+ # == Active Model Presence Validator
7
+ module Validations
8
+ module ActiveModel
9
+ extend ActiveSupport::Concern
10
+
11
+ class ProcessingValidator < ::ActiveModel::EachValidator
12
+
13
+ def validate_each(record, attribute, value)
14
+ record.__send__("#{attribute}_processing_errors").each do |e|
15
+ record.errors.add(attribute, :carrierwave_processing_error, message: (e.message != e.class.to_s) && e.message)
16
+ end
17
+ end
18
+ end
19
+
20
+ class IntegrityValidator < ::ActiveModel::EachValidator
21
+
22
+ def validate_each(record, attribute, value)
23
+ record.__send__("#{attribute}_integrity_errors").each do |e|
24
+ record.errors.add(attribute, :carrierwave_integrity_error, message: (e.message != e.class.to_s) && e.message)
25
+ end
26
+ end
27
+ end
28
+
29
+ class DownloadValidator < ::ActiveModel::EachValidator
30
+
31
+ def validate_each(record, attribute, value)
32
+ record.__send__("#{attribute}_download_errors").each do |e|
33
+ record.errors.add(attribute, :carrierwave_download_error, message: (e.message != e.class.to_s) && e.message)
34
+ end
35
+ end
36
+ end
37
+
38
+ module HelperMethods
39
+
40
+ ##
41
+ # Makes the record invalid if the file couldn't be uploaded due to an integrity error
42
+ #
43
+ # Accepts the usual parameters for validations in Rails (:if, :unless, etc...)
44
+ #
45
+ def validates_integrity_of(*attr_names)
46
+ validates_with IntegrityValidator, _merge_attributes(attr_names)
47
+ end
48
+
49
+ ##
50
+ # Makes the record invalid if the file couldn't be processed (assuming the process failed
51
+ # with a CarrierWave::ProcessingError)
52
+ #
53
+ # Accepts the usual parameters for validations in Rails (:if, :unless, etc...)
54
+ #
55
+ def validates_processing_of(*attr_names)
56
+ validates_with ProcessingValidator, _merge_attributes(attr_names)
57
+ end
58
+
59
+ #
60
+ ##
61
+ # Makes the record invalid if the remote file couldn't be downloaded
62
+ #
63
+ # Accepts the usual parameters for validations in Rails (:if, :unless, etc...)
64
+ #
65
+ def validates_download_of(*attr_names)
66
+ validates_with DownloadValidator, _merge_attributes(attr_names)
67
+ end
68
+ end
69
+
70
+ included do
71
+ extend HelperMethods
72
+ include HelperMethods
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ module CarrierWave
2
+ VERSION = "3.1.3".freeze
3
+ end
@@ -0,0 +1,108 @@
1
+ require 'fileutils'
2
+ require 'active_support/core_ext/object/blank'
3
+ require 'active_support/core_ext/object/try'
4
+ require 'active_support/core_ext/class/attribute'
5
+ require 'active_support/concern'
6
+ require 'active_support/deprecation'
7
+
8
+ module CarrierWave
9
+
10
+ class << self
11
+ attr_accessor :root, :base_path
12
+ attr_writer :tmp_path
13
+
14
+ def configure(&block)
15
+ CarrierWave::Uploader::Base.configure(&block)
16
+ end
17
+
18
+ def clean_cached_files!(seconds=60*60*24)
19
+ CarrierWave::Uploader::Base.clean_cached_files!(seconds)
20
+ end
21
+
22
+ def tmp_path
23
+ @tmp_path ||= File.expand_path(File.join('..', 'tmp'), root)
24
+ end
25
+
26
+ def deprecator
27
+ @deprecator ||= ActiveSupport::Deprecation.new("#{CarrierWave::VERSION.split('.')[0].to_i + 1}.0", "CarrierWave")
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ if defined?(Jets)
34
+
35
+ module CarrierWave
36
+ class Turbine < Jets::Turbine
37
+ initializer "carrierwave.setup_paths" do |app|
38
+ CarrierWave.root = Jets.root.to_s
39
+ CarrierWave.tmp_path = "/tmp/carrierwave"
40
+ CarrierWave.configure do |config|
41
+ config.cache_dir = "/tmp/carrierwave/uploads/tmp"
42
+ end
43
+ end
44
+
45
+ initializer "carrierwave.active_record" do
46
+ ActiveSupport.on_load :active_record do
47
+ require 'carrierwave/orm/activerecord'
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ elsif defined?(Rails)
54
+
55
+ module CarrierWave
56
+ class Railtie < Rails::Railtie
57
+ initializer "carrierwave.setup_paths" do |app|
58
+ CarrierWave.root = Rails.root.join(Rails.public_path).to_s
59
+ CarrierWave.base_path = ENV['RAILS_RELATIVE_URL_ROOT']
60
+ available_locales = Array(app.config.i18n.available_locales || [])
61
+ if available_locales.blank? || available_locales.include?(:en)
62
+ I18n.load_path.prepend(File.join(File.dirname(__FILE__), 'carrierwave', 'locale', "en.yml"))
63
+ end
64
+ end
65
+
66
+ initializer "carrierwave.active_record" do
67
+ ActiveSupport.on_load :active_record do
68
+ require 'carrierwave/orm/activerecord'
69
+ end
70
+ end
71
+
72
+ initializer "carrierwave.deprecator" do |app|
73
+ app.deprecators[:carrierwave] = CarrierWave.deprecator if app.respond_to?(:deprecators)
74
+ end
75
+
76
+ config.before_eager_load do
77
+ CarrierWave::Storage::Fog.eager_load
78
+ end
79
+ end
80
+ end
81
+
82
+ elsif defined?(Sinatra)
83
+ if defined?(Padrino) && defined?(PADRINO_ROOT)
84
+ CarrierWave.root = File.join(PADRINO_ROOT, "public")
85
+ else
86
+
87
+ CarrierWave.root =
88
+ if Sinatra::Application.respond_to?(:public_folder)
89
+ # Sinatra >= 1.3
90
+ Sinatra::Application.public_folder
91
+ else
92
+ # Sinatra < 1.3
93
+ Sinatra::Application.public
94
+ end
95
+ end
96
+ end
97
+
98
+ require "carrierwave/utilities"
99
+ require "carrierwave/error"
100
+ require "carrierwave/sanitized_file"
101
+ require "carrierwave/mounter"
102
+ require "carrierwave/mount"
103
+ require "carrierwave/processing"
104
+ require "carrierwave/version"
105
+ require "carrierwave/storage"
106
+ require "carrierwave/uploader"
107
+ require "carrierwave/compatibility/paperclip"
108
+ require "carrierwave/test/matchers"