dsturnbull-carrierwave 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/Generators +4 -0
  2. data/History.txt +118 -0
  3. data/Manifest.txt +107 -0
  4. data/README.rdoc +502 -0
  5. data/Rakefile +38 -0
  6. data/cucumber.yml +2 -0
  7. data/features/caching.feature +28 -0
  8. data/features/download.feature +20 -0
  9. data/features/file_storage.feature +37 -0
  10. data/features/file_storage_overridden_filename.feature +38 -0
  11. data/features/file_storage_overridden_store_dir.feature +38 -0
  12. data/features/file_storage_reversing_processor.feature +43 -0
  13. data/features/fixtures/bork.txt +1 -0
  14. data/features/fixtures/monkey.txt +1 -0
  15. data/features/grid_fs_storage.feature +32 -0
  16. data/features/mount_activerecord.feature +46 -0
  17. data/features/mount_datamapper.feature +46 -0
  18. data/features/step_definitions/activerecord_steps.rb +22 -0
  19. data/features/step_definitions/caching_steps.rb +14 -0
  20. data/features/step_definitions/datamapper_steps.rb +29 -0
  21. data/features/step_definitions/download_steps.rb +4 -0
  22. data/features/step_definitions/file_steps.rb +53 -0
  23. data/features/step_definitions/general_steps.rb +85 -0
  24. data/features/step_definitions/mount_steps.rb +19 -0
  25. data/features/step_definitions/store_steps.rb +18 -0
  26. data/features/support/activerecord.rb +30 -0
  27. data/features/support/datamapper.rb +7 -0
  28. data/features/support/env.rb +22 -0
  29. data/features/versions_basics.feature +50 -0
  30. data/features/versions_nested_versions.feature +70 -0
  31. data/features/versions_overridden_filename.feature +51 -0
  32. data/features/versions_overriden_store_dir.feature +41 -0
  33. data/lib/carrierwave/compatibility/paperclip.rb +95 -0
  34. data/lib/carrierwave/core_ext/blank.rb +46 -0
  35. data/lib/carrierwave/core_ext/inheritable_attributes.rb +104 -0
  36. data/lib/carrierwave/core_ext/module_setup.rb +51 -0
  37. data/lib/carrierwave/mount.rb +359 -0
  38. data/lib/carrierwave/orm/activerecord.rb +73 -0
  39. data/lib/carrierwave/orm/datamapper.rb +27 -0
  40. data/lib/carrierwave/orm/mongoid.rb +23 -0
  41. data/lib/carrierwave/orm/mongomapper.rb +27 -0
  42. data/lib/carrierwave/orm/sequel.rb +45 -0
  43. data/lib/carrierwave/processing/image_science.rb +101 -0
  44. data/lib/carrierwave/processing/mini_magick.rb +269 -0
  45. data/lib/carrierwave/processing/rmagick.rb +282 -0
  46. data/lib/carrierwave/sanitized_file.rb +268 -0
  47. data/lib/carrierwave/storage/abstract.rb +30 -0
  48. data/lib/carrierwave/storage/file.rb +48 -0
  49. data/lib/carrierwave/storage/grid_fs.rb +96 -0
  50. data/lib/carrierwave/storage/right_s3.rb +170 -0
  51. data/lib/carrierwave/storage/s3.rb +199 -0
  52. data/lib/carrierwave/test/matchers.rb +128 -0
  53. data/lib/carrierwave/uploader/cache.rb +145 -0
  54. data/lib/carrierwave/uploader/callbacks.rb +42 -0
  55. data/lib/carrierwave/uploader/configuration.rb +122 -0
  56. data/lib/carrierwave/uploader/default_url.rb +19 -0
  57. data/lib/carrierwave/uploader/download.rb +59 -0
  58. data/lib/carrierwave/uploader/extension_whitelist.rb +37 -0
  59. data/lib/carrierwave/uploader/mountable.rb +39 -0
  60. data/lib/carrierwave/uploader/processing.rb +83 -0
  61. data/lib/carrierwave/uploader/proxy.rb +62 -0
  62. data/lib/carrierwave/uploader/remove.rb +22 -0
  63. data/lib/carrierwave/uploader/store.rb +89 -0
  64. data/lib/carrierwave/uploader/url.rb +24 -0
  65. data/lib/carrierwave/uploader/versions.rb +146 -0
  66. data/lib/carrierwave/uploader.rb +44 -0
  67. data/lib/carrierwave.rb +96 -0
  68. data/merb_generators/uploader_generator.rb +22 -0
  69. data/rails_generators/uploader/USAGE +2 -0
  70. data/rails_generators/uploader/templates/uploader.rb +47 -0
  71. data/rails_generators/uploader/uploader_generator.rb +21 -0
  72. data/script/console +10 -0
  73. data/script/destroy +14 -0
  74. data/script/generate +14 -0
  75. data/spec/compatibility/paperclip_spec.rb +52 -0
  76. data/spec/fixtures/bork.txt +1 -0
  77. data/spec/fixtures/landscape.jpg +0 -0
  78. data/spec/fixtures/portrait.jpg +0 -0
  79. data/spec/fixtures/test.jpeg +1 -0
  80. data/spec/fixtures/test.jpg +1 -0
  81. data/spec/mount_spec.rb +538 -0
  82. data/spec/orm/activerecord_spec.rb +271 -0
  83. data/spec/orm/datamapper_spec.rb +168 -0
  84. data/spec/orm/mongoid_spec.rb +206 -0
  85. data/spec/orm/mongomapper_spec.rb +202 -0
  86. data/spec/orm/sequel_spec.rb +183 -0
  87. data/spec/processing/image_science_spec.rb +56 -0
  88. data/spec/processing/mini_magick_spec.rb +76 -0
  89. data/spec/processing/rmagick_spec.rb +75 -0
  90. data/spec/sanitized_file_spec.rb +601 -0
  91. data/spec/spec_helper.rb +99 -0
  92. data/spec/storage/grid_fs_spec.rb +82 -0
  93. data/spec/storage/right_s3_spec.rb +75 -0
  94. data/spec/storage/s3_spec.rb +95 -0
  95. data/spec/uploader/cache_spec.rb +209 -0
  96. data/spec/uploader/configuration_spec.rb +105 -0
  97. data/spec/uploader/default_url_spec.rb +85 -0
  98. data/spec/uploader/download_spec.rb +75 -0
  99. data/spec/uploader/extension_whitelist_spec.rb +44 -0
  100. data/spec/uploader/mountable_spec.rb +33 -0
  101. data/spec/uploader/paths_spec.rb +22 -0
  102. data/spec/uploader/processing_spec.rb +73 -0
  103. data/spec/uploader/proxy_spec.rb +54 -0
  104. data/spec/uploader/remove_spec.rb +70 -0
  105. data/spec/uploader/store_spec.rb +248 -0
  106. data/spec/uploader/url_spec.rb +87 -0
  107. data/spec/uploader/versions_spec.rb +298 -0
  108. metadata +351 -0
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ require 'net/http'
4
+
5
+ module CarrierWave
6
+ module Uploader
7
+ module Download
8
+
9
+ depends_on CarrierWave::Uploader::Callbacks
10
+ depends_on CarrierWave::Uploader::Configuration
11
+ depends_on CarrierWave::Uploader::Cache
12
+
13
+ class RemoteFile
14
+ def initialize(uri)
15
+ @uri = URI.parse(uri)
16
+ end
17
+
18
+ def original_filename
19
+ File.basename(@uri.path)
20
+ end
21
+
22
+ def respond_to?(*args)
23
+ super or file.respond_to?(*args)
24
+ end
25
+
26
+ def http?
27
+ @uri.scheme =~ /^https?$/
28
+ end
29
+
30
+ private
31
+
32
+ def file
33
+ @file ||= StringIO.new(Net::HTTP.get_response(@uri).body)
34
+ end
35
+
36
+ def method_missing(*args, &block)
37
+ file.send(*args, &block)
38
+ end
39
+ end
40
+
41
+ ##
42
+ # Caches the file by downloading it from the given URL.
43
+ #
44
+ # === Parameters
45
+ #
46
+ # [url (String)] The URL where the remote file is stored
47
+ #
48
+ def download!(uri)
49
+ unless uri.blank?
50
+ file = RemoteFile.new(uri)
51
+ raise CarrierWave::DownloadError, "trying to download a file which is not served over HTTP" unless file.http?
52
+ cache!(file)
53
+ end
54
+ end
55
+
56
+ end # Download
57
+ end # Uploader
58
+ end # CarrierWave
59
+
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+ module Uploader
5
+ module ExtensionWhitelist
6
+
7
+ setup do
8
+ before :cache, :check_whitelist!
9
+ end
10
+
11
+ ##
12
+ # Override this method in your uploader to provide a white list of extensions which
13
+ # are allowed to be uploaded.
14
+ #
15
+ # === Returns
16
+ #
17
+ # [NilClass, Array[String]] a white list of extensions which are allowed to be uploaded
18
+ #
19
+ # === Examples
20
+ #
21
+ # def extension_white_list
22
+ # %w(jpg jpeg gif png)
23
+ # end
24
+ #
25
+ def extension_white_list; end
26
+
27
+ private
28
+
29
+ def check_whitelist!(new_file)
30
+ if extension_white_list and not extension_white_list.include?(new_file.extension.to_s)
31
+ raise CarrierWave::IntegrityError, "You are not allowed to upload #{new_file.extension.inspect} files, allowed types: #{extension_white_list.inspect}"
32
+ end
33
+ end
34
+
35
+ end # ExtensionWhitelist
36
+ end # Uploader
37
+ end # CarrierWave
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+ module Uploader
5
+ module Mountable
6
+
7
+ attr_reader :model, :mounted_as
8
+
9
+ ##
10
+ # If a model is given as the first parameter, it will stored in the uploader, and
11
+ # available throught +#model+. Likewise, mounted_as stores the name of the column
12
+ # where this instance of the uploader is mounted. These values can then be used inside
13
+ # your uploader.
14
+ #
15
+ # If you do not wish to mount your uploaders with the ORM extensions in -more then you
16
+ # can override this method inside your uploader. Just be sure to call +super+
17
+ #
18
+ # === Parameters
19
+ #
20
+ # [model (Object)] Any kind of model object
21
+ # [mounted_as (Symbol)] The name of the column where this uploader is mounted
22
+ #
23
+ # === Examples
24
+ #
25
+ # class MyUploader < CarrierWave::Uploader::Base
26
+ #
27
+ # def store_dir
28
+ # File.join('public', 'files', mounted_as, model.permalink)
29
+ # end
30
+ # end
31
+ #
32
+ def initialize(model=nil, mounted_as=nil)
33
+ @model = model
34
+ @mounted_as = mounted_as
35
+ end
36
+
37
+ end # Mountable
38
+ end # Uploader
39
+ end # CarrierWave
@@ -0,0 +1,83 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+ module Uploader
5
+ module Processing
6
+
7
+ depends_on CarrierWave::Uploader::Callbacks
8
+
9
+ setup do
10
+ after :cache, :process!
11
+ end
12
+
13
+ module ClassMethods
14
+
15
+ ##
16
+ # Lists processor callbacks declared
17
+ #
18
+ # === Returns
19
+ #
20
+ # [Array[Array[Symbol, Array]]] a list of processor callbacks which have been declared for this uploader
21
+ #
22
+ def processors
23
+ @processors ||= []
24
+ end
25
+
26
+ ##
27
+ # Adds a processor callback which applies operations as a file is uploaded.
28
+ # The argument may be the name of any method of the uploader, expressed as a symbol,
29
+ # or a list of such methods, or a hash where the key is a method and the value is
30
+ # an array of arguments to call the method with
31
+ #
32
+ # === Parameters
33
+ #
34
+ # args (*Symbol, Hash{Symbol => Array[]})
35
+ #
36
+ # === Examples
37
+ #
38
+ # class MyUploader < CarrierWave::Uploader::Base
39
+ #
40
+ # process :sepiatone, :vignette
41
+ # process :scale => [200, 200]
42
+ #
43
+ # def sepiatone
44
+ # ...
45
+ # end
46
+ #
47
+ # def vignette
48
+ # ...
49
+ # end
50
+ #
51
+ # def scale(height, width)
52
+ # ...
53
+ # end
54
+ # end
55
+ #
56
+ def process(*args)
57
+ args.each do |arg|
58
+ if arg.is_a?(Hash)
59
+ arg.each do |method, args|
60
+ processors.push([method, args])
61
+ end
62
+ else
63
+ processors.push([arg, []])
64
+ end
65
+ end
66
+ end
67
+
68
+ end # ClassMethods
69
+
70
+ ##
71
+ # Apply all process callbacks added through CarrierWave.process
72
+ #
73
+ def process!(new_file=nil)
74
+ if enable_processing
75
+ self.class.processors.each do |method, args|
76
+ self.send(method, *args)
77
+ end
78
+ end
79
+ end
80
+
81
+ end # Processing
82
+ end # Uploader
83
+ end # CarrierWave
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+ module Uploader
5
+ module Proxy
6
+
7
+ ##
8
+ # === Returns
9
+ #
10
+ # [Boolean] Whether the uploaded file is blank
11
+ #
12
+ def blank?
13
+ file.blank?
14
+ end
15
+
16
+ ##
17
+ # === Returns
18
+ #
19
+ # [String] the path where the file is currently located.
20
+ #
21
+ def current_path
22
+ file.path if file.respond_to?(:path)
23
+ end
24
+
25
+ alias_method :path, :current_path
26
+
27
+ ##
28
+ # Returns a string that uniquely identifies the last stored file
29
+ #
30
+ # === Returns
31
+ #
32
+ # [String] uniquely identifies a file
33
+ #
34
+ def identifier
35
+ storage.identifier if storage.respond_to?(:identifier)
36
+ end
37
+
38
+ ##
39
+ # Read the contents of the file
40
+ #
41
+ # === Returns
42
+ #
43
+ # [String] contents of the file
44
+ #
45
+ def read
46
+ file.read if file.respond_to?(:read)
47
+ end
48
+
49
+ ##
50
+ # Fetches the size of the currently stored/cached file
51
+ #
52
+ # === Returns
53
+ #
54
+ # [Integer] size of the file
55
+ #
56
+ def size
57
+ file.respond_to?(:size) ? file.size : 0
58
+ end
59
+
60
+ end # Proxy
61
+ end # Uploader
62
+ end # CarrierWave
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+ module Uploader
5
+ module Remove
6
+
7
+ depends_on CarrierWave::Uploader::Callbacks
8
+
9
+ ##
10
+ # Removes the file and reset it
11
+ #
12
+ def remove!
13
+ with_callbacks(:remove) do
14
+ @file.delete if @file
15
+ @file = nil
16
+ @cache_id = nil
17
+ end
18
+ end
19
+
20
+ end # Remove
21
+ end # Uploader
22
+ end # CarrierWave
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+ module Uploader
5
+ module Store
6
+
7
+ depends_on CarrierWave::Uploader::Callbacks
8
+ depends_on CarrierWave::Uploader::Configuration
9
+ depends_on CarrierWave::Uploader::Cache
10
+
11
+ ##
12
+ # Override this in your Uploader to change the filename.
13
+ #
14
+ # Be careful using record ids as filenames. If the filename is stored in the database
15
+ # the record id will be nil when the filename is set. Don't use record ids unless you
16
+ # understand this limitation.
17
+ #
18
+ # Do not use the version_name in the filename, as it will prevent versions from being
19
+ # loaded correctly.
20
+ #
21
+ # === Returns
22
+ #
23
+ # [String] a filename
24
+ #
25
+ def filename
26
+ @filename
27
+ end
28
+
29
+ ##
30
+ # Calculates the path where the file should be stored. If +for_file+ is given, it will be
31
+ # used as the filename, otherwise +CarrierWave::Uploader#filename+ is assumed.
32
+ #
33
+ # === Parameters
34
+ #
35
+ # [for_file (String)] name of the file <optional>
36
+ #
37
+ # === Returns
38
+ #
39
+ # [String] the store path
40
+ #
41
+ def store_path(for_file=filename)
42
+ File.join(store_dir, full_filename(for_file))
43
+ end
44
+
45
+ ##
46
+ # Stores the file by passing it to this Uploader's storage engine.
47
+ #
48
+ # If new_file is omitted, a previously cached file will be stored.
49
+ #
50
+ # === Parameters
51
+ #
52
+ # [new_file (File, IOString, Tempfile)] any kind of file object
53
+ #
54
+ def store!(new_file=nil)
55
+ cache!(new_file) if new_file
56
+ if @file and @cache_id
57
+ with_callbacks(:store, new_file) do
58
+ @file = storage.store!(@file)
59
+ @cache_id = nil
60
+ end
61
+ end
62
+ end
63
+
64
+ ##
65
+ # Retrieves the file from the storage.
66
+ #
67
+ # === Parameters
68
+ #
69
+ # [identifier (String)] uniquely identifies the file to retrieve
70
+ #
71
+ def retrieve_from_store!(identifier)
72
+ with_callbacks(:retrieve_from_store, identifier) do
73
+ @file = storage.retrieve!(identifier)
74
+ end
75
+ end
76
+
77
+ private
78
+
79
+ def full_filename(for_file)
80
+ for_file
81
+ end
82
+
83
+ def storage
84
+ @storage ||= self.class.storage.new(self)
85
+ end
86
+
87
+ end # Store
88
+ end # Uploader
89
+ end # CarrierWave
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+ module Uploader
5
+ module Url
6
+
7
+ ##
8
+ # === Returns
9
+ #
10
+ # [String] the location where this file is accessible via a url
11
+ #
12
+ def url
13
+ if file.respond_to?(:url) and not file.url.blank?
14
+ file.url
15
+ elsif current_path
16
+ File.expand_path(current_path).gsub(File.expand_path(root), '')
17
+ end
18
+ end
19
+
20
+ alias_method :to_s, :url
21
+
22
+ end # Url
23
+ end # Uploader
24
+ end # CarrierWave
@@ -0,0 +1,146 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+ module Uploader
5
+ module Versions
6
+
7
+ depends_on CarrierWave::Uploader::Callbacks
8
+
9
+ setup do
10
+ after :cache, :cache_versions!
11
+ after :store, :store_versions!
12
+ after :remove, :remove_versions!
13
+ after :retrieve_from_cache, :retrieve_versions_from_cache!
14
+ after :retrieve_from_store, :retrieve_versions_from_store!
15
+ end
16
+
17
+ module ClassMethods
18
+
19
+ def version_names
20
+ @version_names ||= []
21
+ end
22
+
23
+ ##
24
+ # Adds a new version to this uploader
25
+ #
26
+ # === Parameters
27
+ #
28
+ # [name (#to_sym)] name of the version
29
+ # [&block (Proc)] a block to eval on this version of the uploader
30
+ #
31
+ def version(name, &block)
32
+ name = name.to_sym
33
+ unless versions[name]
34
+ versions[name] = Class.new(self)
35
+ versions[name].version_names.push(*version_names)
36
+ versions[name].version_names.push(name)
37
+ class_eval <<-RUBY
38
+ def #{name}
39
+ versions[:#{name}]
40
+ end
41
+ RUBY
42
+ end
43
+ versions[name].class_eval(&block) if block
44
+ versions[name]
45
+ end
46
+
47
+ ##
48
+ # === Returns
49
+ #
50
+ # [Hash{Symbol => Class}] a list of versions available for this uploader
51
+ #
52
+ def versions
53
+ @versions ||= {}
54
+ end
55
+
56
+ end # ClassMethods
57
+
58
+ ##
59
+ # Returns a hash mapping the name of each version of the uploader to an instance of it
60
+ #
61
+ # === Returns
62
+ #
63
+ # [Hash{Symbol => CarrierWave::Uploader}] a list of uploader instances
64
+ #
65
+ def versions
66
+ return @versions if @versions
67
+ @versions = {}
68
+ self.class.versions.each do |name, klass|
69
+ @versions[name] = klass.new(model, mounted_as)
70
+ end
71
+ @versions
72
+ end
73
+
74
+ ##
75
+ # === Returns
76
+ #
77
+ # [String] the name of this version of the uploader
78
+ #
79
+ def version_name
80
+ self.class.version_names.join('_').to_sym unless self.class.version_names.blank?
81
+ end
82
+
83
+ ##
84
+ # When given a version name as a parameter, will return the url for that version
85
+ # This also works with nested versions.
86
+ #
87
+ # === Example
88
+ #
89
+ # my_uploader.url # => /path/to/my/uploader.gif
90
+ # my_uploader.url(:thumb) # => /path/to/my/thumb_uploader.gif
91
+ # my_uploader.url(:thumb, :small) # => /path/to/my/thumb_small_uploader.gif
92
+ #
93
+ # === Parameters
94
+ #
95
+ # [*args (Symbol)] any number of versions
96
+ #
97
+ # === Returns
98
+ #
99
+ # [String] the location where this file is accessible via a url
100
+ #
101
+ def url(*args)
102
+ if(args.first)
103
+ raise ArgumentError, "Version #{args.first} doesn't exist!" if versions[args.first.to_sym].nil?
104
+ # recursively proxy to version
105
+ versions[args.first.to_sym].url(*args[1..-1])
106
+ else
107
+ super()
108
+ end
109
+ end
110
+
111
+ private
112
+
113
+ def full_filename(for_file)
114
+ [version_name, super(for_file)].compact.join('_')
115
+ end
116
+
117
+ def full_original_filename
118
+ [version_name, super].compact.join('_')
119
+ end
120
+
121
+ def cache_versions!(new_file)
122
+ versions.each do |name, v|
123
+ v.send(:cache_id=, cache_id)
124
+ v.cache!(new_file)
125
+ end
126
+ end
127
+
128
+ def store_versions!(new_file)
129
+ versions.each { |name, v| v.store!(new_file) }
130
+ end
131
+
132
+ def remove_versions!
133
+ versions.each { |name, v| v.remove! }
134
+ end
135
+
136
+ def retrieve_versions_from_cache!(cache_name)
137
+ versions.each { |name, v| v.retrieve_from_cache!(cache_name) }
138
+ end
139
+
140
+ def retrieve_versions_from_store!(identifier)
141
+ versions.each { |name, v| v.retrieve_from_store!(identifier) }
142
+ end
143
+
144
+ end # Versions
145
+ end # Uploader
146
+ end # CarrierWave
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+
5
+ ##
6
+ # See CarrierWave::Uploader::Base
7
+ #
8
+ module Uploader
9
+
10
+ ##
11
+ # An uploader is a class that allows you to easily handle the caching and storage of
12
+ # uploaded files. Please refer to the README for configuration options.
13
+ #
14
+ # Once you have an uploader you can use it in isolation:
15
+ #
16
+ # my_uploader = MyUploader.new
17
+ # my_uploader.cache!(File.open(path_to_file))
18
+ # my_uploader.retrieve_from_store!('monkey.png')
19
+ #
20
+ # Alternatively, you can mount it on an ORM or other persistence layer, with
21
+ # +CarrierWave::Mount#mount_uploader+. There are extensions for activerecord and datamapper
22
+ # these are *very* simple (they are only a dozen lines of code), so adding your own should
23
+ # be trivial.
24
+ #
25
+ class Base
26
+ attr_reader :file
27
+
28
+ use CarrierWave::Uploader::Callbacks
29
+ use CarrierWave::Uploader::Proxy
30
+ use CarrierWave::Uploader::Url
31
+ use CarrierWave::Uploader::Mountable
32
+ use CarrierWave::Uploader::Cache
33
+ use CarrierWave::Uploader::Store
34
+ use CarrierWave::Uploader::Download
35
+ use CarrierWave::Uploader::Remove
36
+ use CarrierWave::Uploader::ExtensionWhitelist
37
+ use CarrierWave::Uploader::Processing
38
+ use CarrierWave::Uploader::Versions
39
+ use CarrierWave::Uploader::DefaultUrl
40
+ use CarrierWave::Uploader::Configuration
41
+ end # Base
42
+
43
+ end # Uploader
44
+ end # CarrierWave
@@ -0,0 +1,96 @@
1
+ # encoding: utf-8
2
+
3
+ require 'fileutils'
4
+ require 'carrierwave/core_ext/blank'
5
+ require 'carrierwave/core_ext/module_setup'
6
+ require 'carrierwave/core_ext/inheritable_attributes'
7
+
8
+ module CarrierWave
9
+
10
+ VERSION = "0.4.5"
11
+
12
+ class << self
13
+ attr_accessor :root
14
+
15
+ def configure(&block)
16
+ CarrierWave::Uploader::Base.configure(&block)
17
+ end
18
+
19
+ def clean_cached_files!
20
+ CarrierWave::Uploader::Base.clean_cached_files!
21
+ end
22
+ end
23
+
24
+ class UploadError < StandardError; end
25
+ class IntegrityError < UploadError; end
26
+ class InvalidParameter < UploadError; end
27
+ class ProcessingError < UploadError; end
28
+ class DownloadError < UploadError; end
29
+
30
+ autoload :SanitizedFile, 'carrierwave/sanitized_file'
31
+ autoload :Mount, 'carrierwave/mount'
32
+ autoload :RMagick, 'carrierwave/processing/rmagick'
33
+ autoload :ImageScience, 'carrierwave/processing/image_science'
34
+ autoload :MiniMagick, 'carrierwave/processing/mini_magick'
35
+
36
+ module Storage
37
+ autoload :Abstract, 'carrierwave/storage/abstract'
38
+ autoload :File, 'carrierwave/storage/file'
39
+ autoload :S3, 'carrierwave/storage/s3'
40
+ autoload :GridFS, 'carrierwave/storage/grid_fs'
41
+ autoload :RightS3, 'carrierwave/storage/right_s3'
42
+ end
43
+
44
+ module Uploader
45
+ autoload :Base, 'carrierwave/uploader'
46
+ autoload :Cache, 'carrierwave/uploader/cache'
47
+ autoload :Store, 'carrierwave/uploader/store'
48
+ autoload :Download, 'carrierwave/uploader/download'
49
+ autoload :Callbacks, 'carrierwave/uploader/callbacks'
50
+ autoload :Processing, 'carrierwave/uploader/processing'
51
+ autoload :Versions, 'carrierwave/uploader/versions'
52
+ autoload :Remove, 'carrierwave/uploader/remove'
53
+ autoload :ExtensionWhitelist, 'carrierwave/uploader/extension_whitelist'
54
+ autoload :DefaultUrl, 'carrierwave/uploader/default_url'
55
+ autoload :Proxy, 'carrierwave/uploader/proxy'
56
+ autoload :Url, 'carrierwave/uploader/url'
57
+ autoload :Mountable, 'carrierwave/uploader/mountable'
58
+ autoload :Configuration, 'carrierwave/uploader/configuration'
59
+ end
60
+
61
+ module Compatibility
62
+ autoload :Paperclip, 'carrierwave/compatibility/paperclip'
63
+ end
64
+
65
+ module Test
66
+ autoload :Matchers, 'carrierwave/test/matchers'
67
+ end
68
+
69
+ end
70
+
71
+ if defined?(Merb)
72
+
73
+ CarrierWave.root = Merb.dir_for(:public)
74
+ Merb::BootLoader.before_app_loads do
75
+ # Setup path for uploaders and load all of them before classes are loaded
76
+ Merb.push_path(:uploaders, Merb.root / 'app' / 'uploaders', '*.rb')
77
+ Dir.glob(File.join(Merb.load_paths[:uploaders])).each {|f| require f }
78
+ end
79
+
80
+ elsif defined?(Rails)
81
+
82
+ CarrierWave.root = File.join(Rails.root, 'public')
83
+ ActiveSupport::Dependencies.load_paths << File.join(Rails.root, "app", "uploaders")
84
+
85
+ elsif defined?(Sinatra)
86
+
87
+ CarrierWave.root = Sinatra::Application.public
88
+
89
+ end
90
+
91
+
92
+ require File.join(File.dirname(__FILE__), "carrierwave", "orm", 'activerecord') if defined?(ActiveRecord)
93
+ require File.join(File.dirname(__FILE__), "carrierwave", "orm", 'datamapper') if defined?(DataMapper)
94
+ require File.join(File.dirname(__FILE__), "carrierwave", "orm", 'sequel') if defined?(Sequel)
95
+ require File.join(File.dirname(__FILE__), "carrierwave", "orm", "mongomapper") if defined?(MongoMapper)
96
+ require File.join(File.dirname(__FILE__), "carrierwave", "orm", "mongoid") if defined?(Mongoid)