carrierwave 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of carrierwave might be problematic. Click here for more details.

data/Manifest.txt CHANGED
@@ -3,6 +3,7 @@ History.txt
3
3
  Manifest.txt
4
4
  README.rdoc
5
5
  Rakefile
6
+ carrierwave.gemspec
6
7
  cucumber.yml
7
8
  features/caching.feature
8
9
  features/download.feature
@@ -33,6 +34,7 @@ features/versions_overriden_store_dir.feature
33
34
  lib/carrierwave.rb
34
35
  lib/carrierwave/compatibility/paperclip.rb
35
36
  lib/carrierwave/core_ext/blank.rb
37
+ lib/carrierwave/core_ext/file.rb
36
38
  lib/carrierwave/core_ext/inheritable_attributes.rb
37
39
  lib/carrierwave/core_ext/module_setup.rb
38
40
  lib/carrierwave/mount.rb
@@ -46,6 +48,7 @@ lib/carrierwave/processing/mini_magick.rb
46
48
  lib/carrierwave/processing/rmagick.rb
47
49
  lib/carrierwave/sanitized_file.rb
48
50
  lib/carrierwave/storage/abstract.rb
51
+ lib/carrierwave/storage/cloud_files.rb
49
52
  lib/carrierwave/storage/file.rb
50
53
  lib/carrierwave/storage/grid_fs.rb
51
54
  lib/carrierwave/storage/right_s3.rb
@@ -89,6 +92,7 @@ spec/processing/mini_magick_spec.rb
89
92
  spec/processing/rmagick_spec.rb
90
93
  spec/sanitized_file_spec.rb
91
94
  spec/spec_helper.rb
95
+ spec/storage/cloudfiles_spec.rb
92
96
  spec/storage/grid_fs_spec.rb
93
97
  spec/storage/right_s3_spec.rb
94
98
  spec/storage/s3_spec.rb
data/README.rdoc CHANGED
@@ -60,7 +60,7 @@ You can use your uploader class to store and retrieve files like this:
60
60
 
61
61
  CarrierWave gives you a +store+ for permanent storage, and a +cache+ for
62
62
  temporary storage. You can use different stores, at the moment a filesystem
63
- store, an Amazon S3 store and a store for MongoDB's GridFS are bundled.
63
+ store, an Amazon S3 store, a Rackspace Cloud Files store, and a store for MongoDB's GridFS are bundled.
64
64
 
65
65
  Most of the time you are going to want to use CarrierWave together with an ORM.
66
66
  It is quite simple to mount uploaders on columns in your model, so you can
@@ -106,7 +106,8 @@ method:
106
106
  end
107
107
  end
108
108
 
109
- This works for the file storage as well as Amazon S3.
109
+ This works for the file storage as well as Amazon S3 and Rackspace Cloud Files.
110
+ Define +store_dir+ as +nil+ if you'd like to store files at the root level.
110
111
 
111
112
  == Securing uploads
112
113
 
@@ -331,6 +332,27 @@ RightAWS library by setting the storage to :right_s3
331
332
  CarrierWave uses the RightAWS S3 Interface directly, meaning that the performance issues
332
333
  mentioned by Jonathan Yurek for paperclip do not apply: http://groups.google.com/group/paperclip-plugin/browse_thread/thread/d4dc166a9a5f0df4#
333
334
 
335
+ == Using Rackspace Cloud Files
336
+
337
+ Cloud Files support requires a {Rackspace Cloud}[http://rackspacecloud.com] username and API key.
338
+ You must also create a container for Carrierwave to use, and mark it public (publish it to the CDN)
339
+
340
+ CarrierWave.configure do |config|
341
+ config.cloud_files_user_name = 'xxxxxx'
342
+ config.cloud_files_api_key = 'xxxxxxxxxxxxxxxxxxxxx'
343
+ config.cloud_files_container = 'name_of_bucket'
344
+ end
345
+
346
+ Do this in an initializer in Rails, and in a +before_app_loads+ block in Merb.
347
+
348
+ And then in your uploader, set the storage to :cloud_files
349
+
350
+ class AvatarUploader < CarrierWave::Uploader::Base
351
+ storage :cloud_files
352
+ end
353
+
354
+ That's it! You can still use the <code>CarrierWave::Uploader#url</code> method to return
355
+ the url to the file on the Cloud Files CDN.
334
356
 
335
357
  == Using MongoDB's GridFS store
336
358
 
@@ -463,6 +485,10 @@ These people have contributed their time and effort to CarrierWave:
463
485
  * Sam Lown
464
486
  * Dave Ott
465
487
  * Quin Hoxie
488
+ * H. Wade Minter
489
+ * Trevor Turk
490
+ * Nicklas Ramhöj
491
+ * Matt Hooks
466
492
 
467
493
  == License
468
494
 
data/Rakefile CHANGED
@@ -29,6 +29,7 @@ $hoe = Hoe.spec 'carrierwave' do
29
29
  self.extra_dev_deps << ['mongoid', '>=0.10.4']
30
30
  self.extra_dev_deps << ['aws-s3', '>=0.6.2']
31
31
  self.extra_dev_deps << ['timecop', '>=0.3.4']
32
+ self.extra_dev_deps << ['json', '>=1.1.9']
32
33
  self.extra_rdoc_files << 'README.rdoc'
33
34
  end
34
35
 
@@ -0,0 +1,85 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{carrierwave}
5
+ s.version = "0.4.4"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Jonas Nicklas"]
9
+ s.date = %q{2010-02-18}
10
+ s.description = %q{* RDoc Documentation {available at Rubyforge}[http://carrierwave.rubyforge.org/rdoc].
11
+ * Source code {hosted at GitHub}[http://github.com/jnicklas/carrierwave]
12
+ * Please {report any issues}[http://github.com/jnicklas/carrierwave/issues] on GitHub
13
+ * Please direct any questions at the {mailing list}[http://groups.google.com/group/carrierwave]
14
+ * Check out the {example app}[http://github.com/jnicklas/carrierwave-example-app]}
15
+ s.email = ["jonas.nicklas@gmail.com"]
16
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "features/fixtures/bork.txt", "features/fixtures/monkey.txt", "README.rdoc"]
17
+ s.files = ["Generators", "History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "cucumber.yml", "features/caching.feature", "features/download.feature", "features/file_storage.feature", "features/file_storage_overridden_filename.feature", "features/file_storage_overridden_store_dir.feature", "features/file_storage_reversing_processor.feature", "features/fixtures/bork.txt", "features/fixtures/monkey.txt", "features/grid_fs_storage.feature", "features/mount_activerecord.feature", "features/mount_datamapper.feature", "features/step_definitions/activerecord_steps.rb", "features/step_definitions/caching_steps.rb", "features/step_definitions/datamapper_steps.rb", "features/step_definitions/download_steps.rb", "features/step_definitions/file_steps.rb", "features/step_definitions/general_steps.rb", "features/step_definitions/mount_steps.rb", "features/step_definitions/store_steps.rb", "features/support/activerecord.rb", "features/support/datamapper.rb", "features/support/env.rb", "features/versions_basics.feature", "features/versions_nested_versions.feature", "features/versions_overridden_filename.feature", "features/versions_overriden_store_dir.feature", "lib/carrierwave.rb", "lib/carrierwave/compatibility/paperclip.rb", "lib/carrierwave/core_ext/blank.rb", "lib/carrierwave/core_ext/inheritable_attributes.rb", "lib/carrierwave/core_ext/module_setup.rb", "lib/carrierwave/mount.rb", "lib/carrierwave/orm/activerecord.rb", "lib/carrierwave/orm/datamapper.rb", "lib/carrierwave/orm/mongoid.rb", "lib/carrierwave/orm/mongomapper.rb", "lib/carrierwave/orm/sequel.rb", "lib/carrierwave/processing/image_science.rb", "lib/carrierwave/processing/mini_magick.rb", "lib/carrierwave/processing/rmagick.rb", "lib/carrierwave/sanitized_file.rb", "lib/carrierwave/storage/abstract.rb", "lib/carrierwave/storage/cloud_files.rb", "lib/carrierwave/storage/file.rb", "lib/carrierwave/storage/grid_fs.rb", "lib/carrierwave/storage/right_s3.rb", "lib/carrierwave/storage/s3.rb", "lib/carrierwave/test/matchers.rb", "lib/carrierwave/uploader.rb", "lib/carrierwave/uploader/cache.rb", "lib/carrierwave/uploader/callbacks.rb", "lib/carrierwave/uploader/configuration.rb", "lib/carrierwave/uploader/default_url.rb", "lib/carrierwave/uploader/download.rb", "lib/carrierwave/uploader/extension_whitelist.rb", "lib/carrierwave/uploader/mountable.rb", "lib/carrierwave/uploader/processing.rb", "lib/carrierwave/uploader/proxy.rb", "lib/carrierwave/uploader/remove.rb", "lib/carrierwave/uploader/store.rb", "lib/carrierwave/uploader/url.rb", "lib/carrierwave/uploader/versions.rb", "merb_generators/uploader_generator.rb", "rails_generators/uploader/USAGE", "rails_generators/uploader/templates/uploader.rb", "rails_generators/uploader/uploader_generator.rb", "script/console", "script/destroy", "script/generate", "spec/compatibility/paperclip_spec.rb", "spec/fixtures/bork.txt", "spec/fixtures/landscape.jpg", "spec/fixtures/portrait.jpg", "spec/fixtures/test.jpeg", "spec/fixtures/test.jpg", "spec/mount_spec.rb", "spec/orm/activerecord_spec.rb", "spec/orm/datamapper_spec.rb", "spec/orm/mongoid_spec.rb", "spec/orm/mongomapper_spec.rb", "spec/orm/sequel_spec.rb", "spec/processing/image_science_spec.rb", "spec/processing/mini_magick_spec.rb", "spec/processing/rmagick_spec.rb", "spec/sanitized_file_spec.rb", "spec/spec_helper.rb", "spec/storage/grid_fs_spec.rb", "spec/storage/right_s3_spec.rb", "spec/storage/s3_spec.rb", "spec/uploader/cache_spec.rb", "spec/uploader/configuration_spec.rb", "spec/uploader/default_url_spec.rb", "spec/uploader/download_spec.rb", "spec/uploader/extension_whitelist_spec.rb", "spec/uploader/mountable_spec.rb", "spec/uploader/paths_spec.rb", "spec/uploader/processing_spec.rb", "spec/uploader/proxy_spec.rb", "spec/uploader/remove_spec.rb", "spec/uploader/store_spec.rb", "spec/uploader/url_spec.rb", "spec/uploader/versions_spec.rb"]
18
+ s.homepage = %q{http://carrierwave.rubyforge.org}
19
+ s.rdoc_options = ["--main", "README.rdoc"]
20
+ s.require_paths = ["lib"]
21
+ s.rubyforge_project = %q{carrierwave}
22
+ s.rubygems_version = %q{1.3.5}
23
+ s.summary = %q{* RDoc Documentation {available at Rubyforge}[http://carrierwave.rubyforge.org/rdoc]}
24
+
25
+ if s.respond_to? :specification_version then
26
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
+ s.specification_version = 3
28
+
29
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
30
+ s.add_development_dependency(%q<newgem>, [">= 1.5.2"])
31
+ s.add_development_dependency(%q<rspec>, [">= 1.2.8"])
32
+ s.add_development_dependency(%q<cucumber>, [">= 0.3.96"])
33
+ s.add_development_dependency(%q<activerecord>, [">= 2.3.3"])
34
+ s.add_development_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
35
+ s.add_development_dependency(%q<dm-core>, [">= 0.9.11"])
36
+ s.add_development_dependency(%q<data_objects>, [">= 0.9.12"])
37
+ s.add_development_dependency(%q<do_sqlite3>, [">= 0.9.11"])
38
+ s.add_development_dependency(%q<sequel>, [">= 3.2.0"])
39
+ s.add_development_dependency(%q<rmagick>, [">= 2.10.0"])
40
+ s.add_development_dependency(%q<mini_magick>, [">= 1.2.5"])
41
+ s.add_development_dependency(%q<mongo_mapper>, [">= 0.6.8"])
42
+ s.add_development_dependency(%q<mongoid>, [">= 0.10.4"])
43
+ s.add_development_dependency(%q<aws-s3>, [">= 0.6.2"])
44
+ s.add_development_dependency(%q<timecop>, [">= 0.3.4"])
45
+ s.add_development_dependency(%q<json>, [">= 1.1.9"])
46
+ s.add_development_dependency(%q<hoe>, [">= 2.4.0"])
47
+ else
48
+ s.add_dependency(%q<newgem>, [">= 1.5.2"])
49
+ s.add_dependency(%q<rspec>, [">= 1.2.8"])
50
+ s.add_dependency(%q<cucumber>, [">= 0.3.96"])
51
+ s.add_dependency(%q<activerecord>, [">= 2.3.3"])
52
+ s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
53
+ s.add_dependency(%q<dm-core>, [">= 0.9.11"])
54
+ s.add_dependency(%q<data_objects>, [">= 0.9.12"])
55
+ s.add_dependency(%q<do_sqlite3>, [">= 0.9.11"])
56
+ s.add_dependency(%q<sequel>, [">= 3.2.0"])
57
+ s.add_dependency(%q<rmagick>, [">= 2.10.0"])
58
+ s.add_dependency(%q<mini_magick>, [">= 1.2.5"])
59
+ s.add_dependency(%q<mongo_mapper>, [">= 0.6.8"])
60
+ s.add_dependency(%q<mongoid>, [">= 0.10.4"])
61
+ s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
62
+ s.add_dependency(%q<timecop>, [">= 0.3.4"])
63
+ s.add_dependency(%q<json>, [">= 1.1.9"])
64
+ s.add_dependency(%q<hoe>, [">= 2.4.0"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<newgem>, [">= 1.5.2"])
68
+ s.add_dependency(%q<rspec>, [">= 1.2.8"])
69
+ s.add_dependency(%q<cucumber>, [">= 0.3.96"])
70
+ s.add_dependency(%q<activerecord>, [">= 2.3.3"])
71
+ s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
72
+ s.add_dependency(%q<dm-core>, [">= 0.9.11"])
73
+ s.add_dependency(%q<data_objects>, [">= 0.9.12"])
74
+ s.add_dependency(%q<do_sqlite3>, [">= 0.9.11"])
75
+ s.add_dependency(%q<sequel>, [">= 3.2.0"])
76
+ s.add_dependency(%q<rmagick>, [">= 2.10.0"])
77
+ s.add_dependency(%q<mini_magick>, [">= 1.2.5"])
78
+ s.add_dependency(%q<mongo_mapper>, [">= 0.6.8"])
79
+ s.add_dependency(%q<mongoid>, [">= 0.10.4"])
80
+ s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
81
+ s.add_dependency(%q<timecop>, [">= 0.3.4"])
82
+ s.add_dependency(%q<json>, [">= 1.1.9"])
83
+ s.add_dependency(%q<hoe>, [">= 2.4.0"])
84
+ end
85
+ end
data/lib/carrierwave.rb CHANGED
@@ -4,10 +4,11 @@ require 'fileutils'
4
4
  require 'carrierwave/core_ext/blank'
5
5
  require 'carrierwave/core_ext/module_setup'
6
6
  require 'carrierwave/core_ext/inheritable_attributes'
7
+ require 'carrierwave/core_ext/file'
7
8
 
8
9
  module CarrierWave
9
10
 
10
- VERSION = "0.4.4"
11
+ VERSION = "0.4.5"
11
12
 
12
13
  class << self
13
14
  attr_accessor :root
@@ -39,6 +40,7 @@ module CarrierWave
39
40
  autoload :S3, 'carrierwave/storage/s3'
40
41
  autoload :GridFS, 'carrierwave/storage/grid_fs'
41
42
  autoload :RightS3, 'carrierwave/storage/right_s3'
43
+ autoload :CloudFiles, 'carrierwave/storage/cloud_files'
42
44
  end
43
45
 
44
46
  module Uploader
@@ -0,0 +1,11 @@
1
+ class File
2
+ def size
3
+ File.size(path)
4
+ end
5
+
6
+ def empty?
7
+ size == 0
8
+ rescue Errno::ENOENT
9
+ false
10
+ end
11
+ end
@@ -64,7 +64,7 @@ module CarrierWave
64
64
 
65
65
  module ClassMethods
66
66
  def convert(format)
67
- process :resize_to_limit => format
67
+ process :convert => format
68
68
  end
69
69
 
70
70
  def resize_to_limit(width, height)
@@ -79,10 +79,6 @@ module CarrierWave
79
79
  process :resize_to_fill => [width, height]
80
80
  end
81
81
 
82
- def resize_and_pad(width, height)
83
- process :resize_to_fit => [width, height]
84
- end
85
-
86
82
  def resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity)
87
83
  process :resize_and_pad => [width, height, background, gravity]
88
84
  end
@@ -0,0 +1,169 @@
1
+ # encoding: utf-8
2
+ require 'cloudfiles'
3
+
4
+ module CarrierWave
5
+ module Storage
6
+
7
+ ##
8
+ # Uploads things to Rackspace Cloud Files webservices using the Rackspace libraries (cloudfiles gem).
9
+ # In order for CarrierWave to connect to Cloud Files, you'll need to specify an username, api key
10
+ # and container
11
+ #
12
+ # CarrierWave.configure do |config|
13
+ # config.cloud_files_username = "xxxxxx"
14
+ # config.cloud_files_api_key = "xxxxxx"
15
+ # config.cloud_files_container = "my_container"
16
+ # end
17
+ #
18
+ #
19
+ # You can set the access policy for the uploaded files:
20
+ #
21
+ # CarrierWave.configure do |config|
22
+ # config.s3_access_policy = 'public-read'
23
+ # end
24
+ #
25
+ #
26
+ class CloudFiles < Abstract
27
+
28
+ class File
29
+
30
+ def initialize(uploader, base, path)
31
+ @uploader = uploader
32
+ @path = path
33
+ @base = base
34
+ end
35
+
36
+ ##
37
+ # Returns the current path/filename of the file on Cloud Files.
38
+ #
39
+ # === Returns
40
+ #
41
+ # [String] A path
42
+ #
43
+ def path
44
+ @path
45
+ end
46
+
47
+ ##
48
+ # Reads the contents of the file from Cloud Files
49
+ #
50
+ # === Returns
51
+ #
52
+ # [String] contents of the file
53
+ #
54
+ def read
55
+ object = cf_container.object(@path)
56
+ @content_type = object.content_type
57
+ object.data
58
+ end
59
+
60
+ ##
61
+ # Remove the file from Cloud Files
62
+ #
63
+ def delete
64
+ cf_container.delete_object(@path)
65
+ end
66
+
67
+ ##
68
+ # Returns the url on the Cloud Files CDN. Note that the parent container must be marked as
69
+ # public for this to work.
70
+ #
71
+ # === Returns
72
+ #
73
+ # [String] file's url
74
+ #
75
+ def url
76
+ cf_container.object(@path).public_url
77
+ end
78
+
79
+ #def metadata
80
+ # s3_object.metadata
81
+ #end
82
+
83
+ def content_type
84
+ cf_container.object(@path).content_type
85
+ end
86
+
87
+ def content_type=(new_content_type)
88
+ headers["content-type"] = new_content_type
89
+ end
90
+
91
+ ##
92
+ # Writes the supplied data into the object on Cloud Files.
93
+ #
94
+ # === Returns
95
+ #
96
+ # boolean
97
+ #
98
+ def store(data,headers={})
99
+ object = cf_container.create_object(@path)
100
+ object.write(data,headers)
101
+ end
102
+
103
+ private
104
+
105
+ def headers
106
+ @headers ||= { }
107
+ end
108
+
109
+ def container
110
+ @uploader.cloud_files_container
111
+ end
112
+
113
+ def connection
114
+ @base.connection
115
+ end
116
+
117
+ def cf_connection
118
+ @cf_connection ||= ::CloudFiles::Connection.new(@uploader.cloud_files_username, @uploader.cloud_files_api_key)
119
+ end
120
+
121
+ def cf_container
122
+ if @cf_container
123
+ @cf_container
124
+ else
125
+ @cf_container = cf_connection.create_container(container)
126
+ @cf_container.make_public
127
+ @cf_container
128
+ end
129
+ end
130
+
131
+
132
+ end
133
+
134
+ ##
135
+ # Store the file on Cloud Files
136
+ #
137
+ # === Parameters
138
+ #
139
+ # [file (CarrierWave::SanitizedFile)] the file to store
140
+ #
141
+ # === Returns
142
+ #
143
+ # [CarrierWave::Storage::RightS3::File] the stored file
144
+ #
145
+ def store!(file)
146
+ cloud_files_options = {'Content-Type' => file.content_type}
147
+ f = CarrierWave::Storage::CloudFiles::File.new(uploader, self, uploader.store_path)
148
+ f.store(file.read,cloud_files_options)
149
+ f
150
+ end
151
+
152
+ # Do something to retrieve the file
153
+ #
154
+ # @param [String] identifier uniquely identifies the file
155
+ #
156
+ # [identifier (String)] uniquely identifies the file
157
+ #
158
+ # === Returns
159
+ #
160
+ # [CarrierWave::Storage::RightS3::File] the stored file
161
+ #
162
+ def retrieve!(identifier)
163
+ CarrierWave::Storage::CloudFiles::File.new(uploader, self, uploader.store_path(identifier))
164
+ end
165
+
166
+
167
+ end # CloudFiles
168
+ end # Storage
169
+ end # CarrierWave
@@ -82,10 +82,11 @@ module CarrierWave
82
82
  def database
83
83
  @connection ||= begin
84
84
  host = uploader.grid_fs_host
85
+ port = uploader.grid_fs_port
85
86
  database = uploader.grid_fs_database
86
87
  username = uploader.grid_fs_username
87
88
  password = uploader.grid_fs_password
88
- db = Mongo::Connection.new(host).db(database)
89
+ db = Mongo::Connection.new(host, port).db(database)
89
90
  db.authenticate(username, password) if username && password
90
91
  db
91
92
  end
@@ -93,9 +93,9 @@ module CarrierWave
93
93
  #
94
94
  def url
95
95
  if @uploader.s3_cnamed
96
- ["http://", @uploader.s3_bucket, @path].compact.join('/')
96
+ ["http://", @uploader.s3_bucket, "/", @path].compact.join
97
97
  else
98
- ["http://#{@uploader.s3_bucket}.s3.amazonaws.com", @path].compact.join('/')
98
+ ["http://s3.amazonaws.com/", @uploader.s3_bucket, "/", @path].compact.join
99
99
  end
100
100
  end
101
101
 
@@ -112,7 +112,7 @@ module CarrierWave
112
112
  if @uploader.s3_cnamed
113
113
  ["http://", @uploader.s3_bucket, "/", @path].compact.join
114
114
  else
115
- ["http://s3.amazonaws.com", @uploader.s3_bucket, @path].compact.join('/')
115
+ ["http://s3.amazonaws.com/", @uploader.s3_bucket, "/", @path].compact.join
116
116
  end
117
117
  end
118
118
 
@@ -12,8 +12,13 @@ module CarrierWave
12
12
  add_config :s3_access_key_id
13
13
  add_config :s3_secret_access_key
14
14
  add_config :s3_cnamed
15
+ add_config :s3_headers
16
+ add_config :cloud_files_username
17
+ add_config :cloud_files_api_key
18
+ add_config :cloud_files_container
15
19
  add_config :grid_fs_database
16
20
  add_config :grid_fs_host
21
+ add_config :grid_fs_port
17
22
  add_config :grid_fs_username
18
23
  add_config :grid_fs_password
19
24
  add_config :grid_fs_access_url
@@ -34,13 +39,16 @@ module CarrierWave
34
39
  :file => "CarrierWave::Storage::File",
35
40
  :s3 => "CarrierWave::Storage::S3",
36
41
  :grid_fs => "CarrierWave::Storage::GridFS",
37
- :right_s3 => "CarrierWave::Storage::RightS3"
42
+ :right_s3 => "CarrierWave::Storage::RightS3",
43
+ :cloud_files => "CarrierWave::Storage::CloudFiles"
38
44
  }
39
45
  config.storage = :file
40
46
  config.s3_access = :public_read
41
47
  config.s3_access_policy = 'public-read'
48
+ config.s3_headers = {}
42
49
  config.grid_fs_database = 'carrierwave'
43
50
  config.grid_fs_host = 'localhost'
51
+ config.grid_fs_host = 27017
44
52
  config.store_dir = 'uploads'
45
53
  config.cache_dir = 'uploads/tmp'
46
54
  config.ignore_integrity_errors = true
@@ -39,7 +39,7 @@ module CarrierWave
39
39
  # [String] the store path
40
40
  #
41
41
  def store_path(for_file=filename)
42
- File.join(store_dir, full_filename(for_file))
42
+ File.join([store_dir, full_filename(for_file)].compact)
43
43
  end
44
44
 
45
45
  ##
@@ -19,6 +19,15 @@ module CarrierWave
19
19
 
20
20
  alias_method :to_s, :url
21
21
 
22
+ ##
23
+ # === Returns
24
+ #
25
+ # [String] A JSON serializtion containing this uploader's URL
26
+ #
27
+ def to_json
28
+ { 'url' => url }.to_json
29
+ end
30
+
22
31
  end # Url
23
32
  end # Uploader
24
- end # CarrierWave
33
+ end # CarrierWave
@@ -44,14 +44,14 @@ describe CarrierWave::DataMapper do
44
44
  end
45
45
 
46
46
  it "should return blank uploader when an empty string has been assigned" do
47
- repository(:default).adapter.query("INSERT INTO events (image) VALUES ('')")
47
+ repository(:default).adapter.execute("INSERT INTO events (image) VALUES ('')")
48
48
  @event = @class.first
49
49
 
50
50
  @event.image.should be_blank
51
51
  end
52
52
 
53
53
  it "should retrieve a file from the storage if a value is stored in the database" do
54
- repository(:default).adapter.query("INSERT INTO events (image) VALUES ('test.jpg')")
54
+ repository(:default).adapter.execute("INSERT INTO events (image) VALUES ('test.jpg')")
55
55
  @event = @class.first
56
56
 
57
57
  @event.save
@@ -5,23 +5,19 @@ require 'carrierwave/orm/mongoid'
5
5
 
6
6
  connection = Mongo::Connection.new
7
7
  Mongoid.database = connection.db("carrierwave_test")
8
+
9
+ MongoidUploader = Class.new(CarrierWave::Uploader::Base)
10
+ MongoidUser = Class.new
11
+ MongoidUser.class_eval do
12
+ include Mongoid::Document
13
+ store_in :users
14
+ mount_uploader :image, MongoidUploader
15
+ end
8
16
 
9
17
  describe CarrierWave::Mongoid do
10
18
 
11
- before do
12
- uploader = Class.new(CarrierWave::Uploader::Base)
13
-
14
- @class = Class.new
15
- @class.class_eval do
16
- include Mongoid::Document
17
- mount_uploader :image, uploader
18
- end
19
-
20
- @uploader = uploader
21
- end
22
-
23
19
  after do
24
- @class.collection.drop
20
+ MongoidUser.collection.drop
25
21
  end
26
22
 
27
23
  describe '#image' do
@@ -29,7 +25,7 @@ describe CarrierWave::Mongoid do
29
25
  context "when nothing is assigned" do
30
26
 
31
27
  before do
32
- @document = @class.new
28
+ @document = MongoidUser.new
33
29
  end
34
30
 
35
31
  it "returns a blank uploader" do
@@ -41,12 +37,12 @@ describe CarrierWave::Mongoid do
41
37
  context "when an empty string is assigned" do
42
38
 
43
39
  before do
44
- @document = @class.new(:image_filename => "")
40
+ @document = MongoidUser.new(:image_filename => "")
45
41
  @document.save
46
42
  end
47
43
 
48
44
  it "returns a blank uploader" do
49
- @saved_doc = @class.find(:first)
45
+ @saved_doc = MongoidUser.first
50
46
  @saved_doc.image.should be_blank
51
47
  end
52
48
 
@@ -55,13 +51,13 @@ describe CarrierWave::Mongoid do
55
51
  context "when a filename is saved in the database" do
56
52
 
57
53
  before do
58
- @document = @class.new(:image_filename => "test.jpg")
54
+ @document = MongoidUser.new(:image_filename => "test.jpg")
59
55
  @document.save
60
- @doc = @class.find(:first)
56
+ @doc = MongoidUser.first
61
57
  end
62
58
 
63
59
  it "returns an uploader" do
64
- @doc.image.should be_an_instance_of(@uploader)
60
+ @doc.image.should be_an_instance_of(MongoidUploader)
65
61
  end
66
62
 
67
63
  it "sets the path to the store directory" do
@@ -75,7 +71,7 @@ describe CarrierWave::Mongoid do
75
71
  describe '#image=' do
76
72
 
77
73
  before do
78
- @doc = @class.new
74
+ @doc = MongoidUser.new
79
75
  end
80
76
 
81
77
  context "when nil is assigned" do
@@ -100,7 +96,7 @@ describe CarrierWave::Mongoid do
100
96
 
101
97
  it "should cache a file" do
102
98
  @doc.image = stub_file('test.jpeg')
103
- @doc.image.should be_an_instance_of(@uploader)
99
+ @doc.image.should be_an_instance_of(MongoidUploader)
104
100
  end
105
101
 
106
102
  it "should write nothing to the database, to prevent overriden filenames to fail because of unassigned attributes" do
@@ -119,7 +115,7 @@ describe CarrierWave::Mongoid do
119
115
  describe "#save" do
120
116
 
121
117
  before do
122
- @doc = @class.new
118
+ @doc = MongoidUser.new
123
119
  end
124
120
 
125
121
  context "when no file is assigned" do
@@ -136,7 +132,7 @@ describe CarrierWave::Mongoid do
136
132
  it "copies the file to the upload directory" do
137
133
  @doc.image = stub_file('test.jpg')
138
134
  @doc.save
139
- @doc.image.should be_an_instance_of(@uploader)
135
+ @doc.image.should be_an_instance_of(MongoidUploader)
140
136
  @doc.image.current_path.should == public_path('uploads/test.jpg')
141
137
  end
142
138
 
@@ -166,7 +162,7 @@ describe CarrierWave::Mongoid do
166
162
  describe '#destroy' do
167
163
 
168
164
  before do
169
- @doc = @class.new
165
+ @doc = MongoidUser.new
170
166
  end
171
167
 
172
168
  describe "when file assigned" do
@@ -175,7 +171,7 @@ describe CarrierWave::Mongoid do
175
171
  @doc.image = stub_file('test.jpeg')
176
172
  @doc.save.should be_true
177
173
  File.exist?(public_path('uploads/test.jpeg')).should be_true
178
- @doc.image.should be_an_instance_of(@uploader)
174
+ @doc.image.should be_an_instance_of(MongoidUploader)
179
175
  @doc.image.current_path.should == public_path('uploads/test.jpeg')
180
176
  @doc.destroy
181
177
  File.exist?(public_path('uploads/test.jpeg')).should be_false
@@ -185,16 +181,16 @@ describe CarrierWave::Mongoid do
185
181
 
186
182
  describe "when file is not assigned" do
187
183
 
188
- it "deletes the instance of @class after save" do
184
+ it "deletes the instance of MongoidUser after save" do
189
185
  @doc.save
190
- @class.count.should eql(1)
186
+ MongoidUser.count.should eql(1)
191
187
  @doc.destroy
192
188
  end
193
189
 
194
- it "deletes the instance of @class after save and then re-looking up the instance" do
190
+ it "deletes the instance of MongoidUser after save and then re-looking up the instance" do
195
191
  @doc.save
196
- @class.count.should eql(1)
197
- @doc = @class.first
192
+ MongoidUser.count.should eql(1)
193
+ @doc = MongoidUser.first
198
194
  @doc.destroy
199
195
  end
200
196
 
@@ -41,7 +41,7 @@ describe CarrierWave::MongoMapper do
41
41
  end
42
42
 
43
43
  it "returns a blank uploader" do
44
- @saved_doc = @class.find(:first)
44
+ @saved_doc = @class.first
45
45
  @saved_doc.image.should be_blank
46
46
  end
47
47
 
@@ -52,7 +52,7 @@ describe CarrierWave::MongoMapper do
52
52
  before do
53
53
  @document = @class.new(:image_filename => "test.jpg")
54
54
  @document.save
55
- @doc = @class.find(:first)
55
+ @doc = @class.first
56
56
  end
57
57
 
58
58
  it "returns an uploader" do
@@ -199,4 +199,4 @@ describe CarrierWave::MongoMapper do
199
199
  end
200
200
 
201
201
 
202
- end
202
+ end
@@ -35,9 +35,10 @@ describe CarrierWave::SanitizedFile do
35
35
  end
36
36
 
37
37
  it "should be empty for a file with a zero size" do
38
- empty_file = mock('emptyfile')
39
- empty_file.should_receive(:size).at_least(:once).and_return(0)
40
- @sanitized_file = CarrierWave::SanitizedFile.new(empty_file)
38
+ FileUtils.rm file_path('llama.jpg')
39
+ FileUtils.touch file_path('llama.jpg')
40
+
41
+ @sanitized_file = CarrierWave::SanitizedFile.new(File.open(file_path('llama.jpg')))
41
42
  @sanitized_file.should be_empty
42
43
  end
43
44
 
data/spec/spec_helper.rb CHANGED
@@ -5,14 +5,6 @@ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
5
 
6
6
  require 'rubygems'
7
7
 
8
- if ENV["AS"]
9
- puts "--> using ActiveSupport"
10
- require 'activesupport'
11
- elsif ENV["EXTLIB"]
12
- puts "--> using Extlib"
13
- require 'extlib'
14
- end
15
-
16
8
  require 'tempfile'
17
9
  #require 'ruby-debug'
18
10
  require 'spec'
@@ -21,6 +13,7 @@ require 'spec/autorun'
21
13
  require 'carrierwave'
22
14
  require 'timecop'
23
15
  require 'time'
16
+ require 'json'
24
17
 
25
18
  require 'logger'
26
19
 
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ if ENV['CLOUDFILES_SPEC']
6
+ require 'cloudfiles'
7
+ require 'net/http'
8
+
9
+ describe CarrierWave::Storage::CloudFiles do
10
+ before do
11
+ @uploader = mock('an uploader')
12
+ @uploader.stub!(:cloud_files_username).and_return(ENV["CLOUD_FILES_USER_NAME"])
13
+ @uploader.stub!(:cloud_files_api_key).and_return(ENV["CLOUD_FILES_API_KEY"])
14
+ @uploader.stub!(:cloud_files_container).and_return(ENV['CARRIERWAVE_TEST_CONTAINER'])
15
+ @storage = CarrierWave::Storage::CloudFiles.new(@uploader)
16
+ @file = stub_tempfile('test.jpg', 'application/xml')
17
+
18
+ @cf = CloudFiles::Connection.new(ENV["CLOUD_FILES_USER_NAME"], ENV["CLOUD_FILES_API_KEY"])
19
+ @container = @cf.container(@uploader.cloud_files_container)
20
+ end
21
+
22
+ describe '#store!' do
23
+ before do
24
+ @uploader.stub!(:store_path).and_return('uploads/bar.txt')
25
+ @cloud_file = @storage.store!(@file)
26
+ end
27
+
28
+ it "should upload the file to Cloud Files" do
29
+ @container.object('uploads/bar.txt').data.should == 'this is stuff'
30
+ end
31
+
32
+ it "should have a path" do
33
+ @cloud_file.path.should == 'uploads/bar.txt'
34
+ end
35
+
36
+ it "should have an Rackspace URL" do
37
+ @cloud_file.url.should =~ %r!http://(.*?).cdn.cloudfiles.rackspacecloud.com/uploads/bar.txt!
38
+ end
39
+
40
+ it "should store the content type on Cloud Files" do
41
+ @cloud_file.content_type.should == 'application/xml'
42
+ end
43
+
44
+ it "should be deletable" do
45
+ @cloud_file.delete
46
+ @container.object_exists?('uploads/bar.txt').should be_false
47
+ end
48
+
49
+ end
50
+
51
+ describe '#retrieve!' do
52
+ before do
53
+ @container.create_object('uploads/bar.txt').write("A test, 1234")
54
+ @uploader.stub!(:store_path).with('bar.txt').and_return('uploads/bar.txt')
55
+
56
+ @cloud_file = @storage.retrieve!('bar.txt')
57
+ end
58
+
59
+ it "should retrieve the file contents from Cloud Files" do
60
+ @cloud_file.read.chomp.should == "A test, 1234"
61
+ end
62
+
63
+ it "should have a path" do
64
+ @cloud_file.path.should == 'uploads/bar.txt'
65
+ end
66
+
67
+ it "should have an Rackspace URL" do
68
+ @cloud_file.url.should =~ %r!http://(.*?).cdn.cloudfiles.rackspacecloud.com/uploads/bar.txt!
69
+ end
70
+
71
+ it "should be deletable" do
72
+ @cloud_file.delete
73
+ @container.object_exists?('uploads/bar.txt').should be_false
74
+ end
75
+ end
76
+
77
+ end
78
+ end
@@ -5,10 +5,11 @@ require File.dirname(__FILE__) + '/../spec_helper'
5
5
  describe CarrierWave::Storage::GridFS do
6
6
 
7
7
  before do
8
- @database = Mongo::Connection.new('localhost').db('carrierwave_test')
8
+ @database = Mongo::Connection.new('localhost', 27017).db('carrierwave_test')
9
9
  @uploader = mock('an uploader')
10
10
  @uploader.stub!(:grid_fs_database).and_return("carrierwave_test")
11
11
  @uploader.stub!(:grid_fs_host).and_return("localhost")
12
+ @uploader.stub!(:grid_fs_port).and_return(27017)
12
13
  @uploader.stub!(:grid_fs_access_url).and_return(nil)
13
14
  @uploader.stub!(:grid_fs_username).and_return(nil)
14
15
  @uploader.stub!(:grid_fs_password).and_return(nil)
@@ -79,4 +80,4 @@ describe CarrierWave::Storage::GridFS do
79
80
  end
80
81
  end
81
82
 
82
- end
83
+ end
@@ -39,7 +39,15 @@ if ENV['S3_SPEC']
39
39
  it "should have an Amazon URL" do
40
40
  @s3_file.url.should == "http://#{@bucket}.s3.amazonaws.com/uploads/bar.txt"
41
41
  end
42
-
42
+
43
+ context "with cnamed bucket" do
44
+ it "should have a CNAMED URL" do
45
+ @uploader.stub!(:s3_cnamed).and_return(true)
46
+ @uploader.stub!(:s3_bucket).and_return('foo.bar')
47
+ @s3_file.url.should == 'http://foo.bar/uploads/bar.txt'
48
+ end
49
+ end
50
+
43
51
  it "should be deletable" do
44
52
  @s3_file.delete
45
53
  lambda {@storage.connection.head(@bucket, 'uploads/bar.txt')}.should raise_error(RightAws::AwsError)
@@ -169,6 +169,22 @@ describe CarrierWave::Uploader do
169
169
  end
170
170
  end
171
171
 
172
+ describe 'without a store dir' do
173
+ before do
174
+ @uploader_class.class_eval do
175
+ def store_dir; nil; end
176
+ end
177
+ end
178
+
179
+ it "should create a new file with a valid path and url" do
180
+ @file = File.open(file_path('test.jpg'))
181
+ @uploader.store!(@file)
182
+ @path = ::File.expand_path(@uploader.store_path, @uploader.root)
183
+ File.exist?(@path).should be_true
184
+ @uploader.url.should == '/test.jpg'
185
+ end
186
+ end
187
+
172
188
  describe 'with an overridden, reversing, filename' do
173
189
  before do
174
190
  @uploader_class.class_eval do
@@ -63,6 +63,21 @@ describe CarrierWave::Uploader do
63
63
  end
64
64
  end
65
65
 
66
+ describe '#to_json' do
67
+ before do
68
+ CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
69
+ end
70
+
71
+ it "should return a hash with a blank URL" do
72
+ JSON.parse(@uploader.to_json)['url'].should be_nil
73
+ end
74
+
75
+ it "should return a hash including a cached URL" do
76
+ @uploader.cache!(File.open(file_path('test.jpg')))
77
+ JSON.parse(@uploader.to_json)['url'].should == '/uploads/tmp/20071201-1234-345-2255/test.jpg'
78
+ end
79
+ end
80
+
66
81
  describe '#to_s' do
67
82
  before do
68
83
  CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
@@ -84,4 +99,4 @@ describe CarrierWave::Uploader do
84
99
  end
85
100
  end
86
101
 
87
- end
102
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
@@ -182,6 +182,16 @@ dependencies:
182
182
  - !ruby/object:Gem::Version
183
183
  version: 0.3.4
184
184
  version:
185
+ - !ruby/object:Gem::Dependency
186
+ name: json
187
+ type: :development
188
+ version_requirement:
189
+ version_requirements: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: 1.1.9
194
+ version:
185
195
  - !ruby/object:Gem::Dependency
186
196
  name: hoe
187
197
  type: :development
@@ -216,6 +226,7 @@ files:
216
226
  - Manifest.txt
217
227
  - README.rdoc
218
228
  - Rakefile
229
+ - carrierwave.gemspec
219
230
  - cucumber.yml
220
231
  - features/caching.feature
221
232
  - features/download.feature
@@ -246,6 +257,7 @@ files:
246
257
  - lib/carrierwave.rb
247
258
  - lib/carrierwave/compatibility/paperclip.rb
248
259
  - lib/carrierwave/core_ext/blank.rb
260
+ - lib/carrierwave/core_ext/file.rb
249
261
  - lib/carrierwave/core_ext/inheritable_attributes.rb
250
262
  - lib/carrierwave/core_ext/module_setup.rb
251
263
  - lib/carrierwave/mount.rb
@@ -259,6 +271,7 @@ files:
259
271
  - lib/carrierwave/processing/rmagick.rb
260
272
  - lib/carrierwave/sanitized_file.rb
261
273
  - lib/carrierwave/storage/abstract.rb
274
+ - lib/carrierwave/storage/cloud_files.rb
262
275
  - lib/carrierwave/storage/file.rb
263
276
  - lib/carrierwave/storage/grid_fs.rb
264
277
  - lib/carrierwave/storage/right_s3.rb
@@ -302,6 +315,7 @@ files:
302
315
  - spec/processing/rmagick_spec.rb
303
316
  - spec/sanitized_file_spec.rb
304
317
  - spec/spec_helper.rb
318
+ - spec/storage/cloudfiles_spec.rb
305
319
  - spec/storage/grid_fs_spec.rb
306
320
  - spec/storage/right_s3_spec.rb
307
321
  - spec/storage/s3_spec.rb