carrierwave 0.3.2 → 0.3.3
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/History.txt +68 -0
- data/Manifest.txt +89 -0
- data/README.rdoc +39 -4
- data/Rakefile +32 -115
- data/carrierwave.gemspec +63 -0
- data/cucumber.yml +2 -0
- data/features/caching.feature +28 -0
- data/features/file_storage.feature +37 -0
- data/features/file_storage_overridden_filename.feature +38 -0
- data/features/file_storage_overridden_store_dir.feature +38 -0
- data/features/file_storage_reversing_processor.feature +43 -0
- data/features/fixtures/bork.txt +1 -0
- data/features/fixtures/monkey.txt +1 -0
- data/features/mount_activerecord.feature +46 -0
- data/features/mount_datamapper.feature +46 -0
- data/features/step_definitions/activerecord_steps.rb +22 -0
- data/features/step_definitions/caching_steps.rb +14 -0
- data/features/step_definitions/datamapper_steps.rb +29 -0
- data/features/step_definitions/file_steps.rb +42 -0
- data/features/step_definitions/general_steps.rb +80 -0
- data/features/step_definitions/mount_steps.rb +19 -0
- data/features/step_definitions/store_steps.rb +18 -0
- data/features/support/activerecord.rb +30 -0
- data/features/support/datamapper.rb +7 -0
- data/features/support/env.rb +35 -0
- data/features/versions_basics.feature +50 -0
- data/features/versions_nested_versions.feature +70 -0
- data/features/versions_overridden_filename.feature +51 -0
- data/features/versions_overriden_store_dir.feature +41 -0
- data/lib/carrierwave.rb +8 -0
- data/lib/carrierwave/orm/mongomapper.rb +27 -0
- data/lib/carrierwave/processing/rmagick.rb +6 -4
- data/lib/carrierwave/storage/abstract.rb +5 -5
- data/lib/carrierwave/storage/s3.rb +17 -1
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/orm/mongomapper_spec.rb +184 -0
- metadata +157 -20
- data/LICENSE +0 -20
- data/TODO +0 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
When /^I assign the file '([^\']*)' to the '([^\']*)' column$/ do |path, column|
|
4
|
+
@instance.send("#{column}=", File.open(file_path(path)))
|
5
|
+
end
|
6
|
+
|
7
|
+
Given /^the uploader class is mounted on the '([^\']*)' column$/ do |column|
|
8
|
+
@mountee_klass.mount_uploader column.to_sym, @klass
|
9
|
+
end
|
10
|
+
|
11
|
+
When /^I retrieve the file later from the cache name for the column '([^\']*)'$/ do |column|
|
12
|
+
new_instance = @instance.class.new
|
13
|
+
new_instance.send("#{column}_cache=", @instance.send("#{column}_cache"))
|
14
|
+
@instance = new_instance
|
15
|
+
end
|
16
|
+
|
17
|
+
Then /^the url for the column '([^\']*)' should be '([^\']*)'$/ do |column, url|
|
18
|
+
@instance.send("#{column}_url").should == url
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Given /^the file '(.*?)' is stored at '(.*?)'$/ do |file, stored|
|
4
|
+
FileUtils.mkdir_p(File.dirname(file_path(stored)))
|
5
|
+
FileUtils.cp(file_path(file), file_path(stored))
|
6
|
+
end
|
7
|
+
|
8
|
+
When /^I store the file$/ do
|
9
|
+
@uploader.store!
|
10
|
+
end
|
11
|
+
|
12
|
+
When /^I store the file '(.*?)'$/ do |file|
|
13
|
+
@uploader.store!(File.open(file_path(file)))
|
14
|
+
end
|
15
|
+
|
16
|
+
When /^I retrieve the file '(.*?)' from the store$/ do |identifier|
|
17
|
+
@uploader.retrieve_from_store!(identifier)
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'activerecord'
|
4
|
+
require 'carrierwave/mount'
|
5
|
+
require 'carrierwave/orm/activerecord'
|
6
|
+
|
7
|
+
# change this if sqlite is unavailable
|
8
|
+
dbconfig = {
|
9
|
+
:adapter => 'sqlite3',
|
10
|
+
:database => ':memory:'
|
11
|
+
}
|
12
|
+
|
13
|
+
ActiveRecord::Base.establish_connection(dbconfig)
|
14
|
+
ActiveRecord::Migration.verbose = false
|
15
|
+
|
16
|
+
class TestMigration < ActiveRecord::Migration
|
17
|
+
def self.up
|
18
|
+
create_table :users, :force => true do |t|
|
19
|
+
t.column :avatar, :string
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.down
|
24
|
+
drop_table :users
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Before do
|
29
|
+
TestMigration.up
|
30
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$TESTING=true
|
4
|
+
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require File.join(File.dirname(__FILE__), 'activerecord')
|
8
|
+
require File.join(File.dirname(__FILE__), 'datamapper')
|
9
|
+
|
10
|
+
if ENV["AS"]
|
11
|
+
puts "--> using ActiveSupport"
|
12
|
+
require 'activesupport'
|
13
|
+
elsif ENV["EXTLIB"]
|
14
|
+
puts "--> using Extlib"
|
15
|
+
require 'extlib'
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'tempfile'
|
19
|
+
#require 'ruby-debug'
|
20
|
+
require 'spec'
|
21
|
+
|
22
|
+
require 'carrierwave'
|
23
|
+
|
24
|
+
alias :running :lambda
|
25
|
+
|
26
|
+
def file_path( *paths )
|
27
|
+
File.expand_path(File.join(File.dirname(__FILE__), '..', *paths))
|
28
|
+
end
|
29
|
+
|
30
|
+
CarrierWave.config[:public] = file_path('public')
|
31
|
+
CarrierWave.config[:root] = file_path
|
32
|
+
|
33
|
+
After do
|
34
|
+
FileUtils.rm_rf(file_path("public"))
|
35
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
Feature: uploader with file storage and versions
|
2
|
+
In order to be awesome
|
3
|
+
As a developer using CarrierWave
|
4
|
+
I want to upload files to the filesystem
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given an uploader class that uses the 'file' storage
|
8
|
+
And that the uploader class has a version named 'thumb'
|
9
|
+
And an instance of that class
|
10
|
+
|
11
|
+
Scenario: store a file
|
12
|
+
When I store the file 'fixtures/bork.txt'
|
13
|
+
Then there should be a file at 'public/uploads/bork.txt'
|
14
|
+
Then there should be a file at 'public/uploads/thumb_bork.txt'
|
15
|
+
And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
16
|
+
And the file at 'public/uploads/thumb_bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
17
|
+
And the uploader should have the url '/uploads/bork.txt'
|
18
|
+
And the uploader's version 'thumb' should have the url '/uploads/thumb_bork.txt'
|
19
|
+
|
20
|
+
Scenario: cache a file and then store it
|
21
|
+
When I cache the file 'fixtures/bork.txt'
|
22
|
+
Then there should be a file called 'bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
|
23
|
+
Then there should be a file called 'thumb_bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
|
24
|
+
And the file called 'bork.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/bork.txt'
|
25
|
+
And there should not be a file at 'public/uploads/bork.txt'
|
26
|
+
And there should not be a file at 'public/uploads/thumb_bork.txt'
|
27
|
+
When I store the file
|
28
|
+
Then there should be a file at 'public/uploads/bork.txt'
|
29
|
+
And there should be a file at 'public/uploads/thumb_bork.txt'
|
30
|
+
And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
31
|
+
And the file at 'public/uploads/thumb_bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
32
|
+
And the uploader should have the url '/uploads/bork.txt'
|
33
|
+
And the uploader's version 'thumb' should have the url '/uploads/thumb_bork.txt'
|
34
|
+
|
35
|
+
Scenario: retrieving a file from cache then storing
|
36
|
+
Given the file 'fixtures/bork.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/bork.txt'
|
37
|
+
Given the file 'fixtures/monkey.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/thumb_bork.txt'
|
38
|
+
When I retrieve the cache name '20090212-2343-8336-0348/bork.txt' from the cache
|
39
|
+
And I store the file
|
40
|
+
Then there should be a file at 'public/uploads/bork.txt'
|
41
|
+
Then there should be a file at 'public/uploads/thumb_bork.txt'
|
42
|
+
And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
43
|
+
And the file at 'public/uploads/thumb_bork.txt' should be identical to the file at 'fixtures/monkey.txt'
|
44
|
+
|
45
|
+
Scenario: retrieving a file from store
|
46
|
+
Given the file 'fixtures/bork.txt' is stored at 'public/uploads/bork.txt'
|
47
|
+
Given the file 'fixtures/monkey.txt' is stored at 'public/uploads/thumb_bork.txt'
|
48
|
+
When I retrieve the file 'bork.txt' from the store
|
49
|
+
Then the uploader should have the url '/uploads/bork.txt'
|
50
|
+
And the uploader's version 'thumb' should have the url '/uploads/thumb_bork.txt'
|
@@ -0,0 +1,70 @@
|
|
1
|
+
Feature: uploader with nested versions
|
2
|
+
In order to optimize performance for processing
|
3
|
+
As a developer using CarrierWave
|
4
|
+
I want to set nested versions
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given an uploader class that uses the 'file' storage
|
8
|
+
And that the uploader class has a version named 'thumb'
|
9
|
+
And yo dawg, I put a version called 'mini' in your version called 'thumb'
|
10
|
+
And yo dawg, I put a version called 'micro' in your version called 'thumb'
|
11
|
+
And an instance of that class
|
12
|
+
|
13
|
+
Scenario: store a file
|
14
|
+
When I store the file 'fixtures/bork.txt'
|
15
|
+
Then there should be a file at 'public/uploads/bork.txt'
|
16
|
+
Then there should be a file at 'public/uploads/thumb_bork.txt'
|
17
|
+
Then there should be a file at 'public/uploads/thumb_mini_bork.txt'
|
18
|
+
Then there should be a file at 'public/uploads/thumb_micro_bork.txt'
|
19
|
+
And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
20
|
+
And the file at 'public/uploads/thumb_bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
21
|
+
And the file at 'public/uploads/thumb_mini_bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
22
|
+
And the file at 'public/uploads/thumb_micro_bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
23
|
+
And the uploader should have the url '/uploads/bork.txt'
|
24
|
+
And the uploader's version 'thumb' should have the url '/uploads/thumb_bork.txt'
|
25
|
+
And the uploader's nested version 'mini' nested in 'thumb' should have the url '/uploads/thumb_mini_bork.txt'
|
26
|
+
And the uploader's nested version 'micro' nested in 'thumb' should have the url '/uploads/thumb_micro_bork.txt'
|
27
|
+
|
28
|
+
Scenario: cache a file and then store it
|
29
|
+
When I cache the file 'fixtures/bork.txt'
|
30
|
+
Then there should be a file called 'bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
|
31
|
+
Then there should be a file called 'thumb_bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
|
32
|
+
And the file called 'bork.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/bork.txt'
|
33
|
+
And there should not be a file at 'public/uploads/bork.txt'
|
34
|
+
And there should not be a file at 'public/uploads/thumb_bork.txt'
|
35
|
+
When I store the file
|
36
|
+
Then there should be a file at 'public/uploads/bork.txt'
|
37
|
+
And there should be a file at 'public/uploads/thumb_bork.txt'
|
38
|
+
And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
39
|
+
And the file at 'public/uploads/thumb_bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
40
|
+
And the uploader should have the url '/uploads/bork.txt'
|
41
|
+
And the uploader's version 'thumb' should have the url '/uploads/thumb_bork.txt'
|
42
|
+
And the uploader's nested version 'mini' nested in 'thumb' should have the url '/uploads/thumb_mini_bork.txt'
|
43
|
+
And the uploader's nested version 'micro' nested in 'thumb' should have the url '/uploads/thumb_micro_bork.txt'
|
44
|
+
|
45
|
+
Scenario: retrieving a file from cache then storing
|
46
|
+
Given the file 'fixtures/bork.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/bork.txt'
|
47
|
+
Given the file 'fixtures/monkey.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/thumb_bork.txt'
|
48
|
+
Given the file 'fixtures/bork.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/thumb_mini_bork.txt'
|
49
|
+
Given the file 'fixtures/monkey.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/thumb_micro_bork.txt'
|
50
|
+
When I retrieve the cache name '20090212-2343-8336-0348/bork.txt' from the cache
|
51
|
+
And I store the file
|
52
|
+
Then there should be a file at 'public/uploads/bork.txt'
|
53
|
+
Then there should be a file at 'public/uploads/thumb_bork.txt'
|
54
|
+
Then there should be a file at 'public/uploads/thumb_mini_bork.txt'
|
55
|
+
Then there should be a file at 'public/uploads/thumb_micro_bork.txt'
|
56
|
+
And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
57
|
+
And the file at 'public/uploads/thumb_bork.txt' should be identical to the file at 'fixtures/monkey.txt'
|
58
|
+
And the file at 'public/uploads/thumb_mini_bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
59
|
+
And the file at 'public/uploads/thumb_micro_bork.txt' should be identical to the file at 'fixtures/monkey.txt'
|
60
|
+
|
61
|
+
Scenario: retrieving a file from store
|
62
|
+
Given the file 'fixtures/bork.txt' is stored at 'public/uploads/bork.txt'
|
63
|
+
Given the file 'fixtures/monkey.txt' is stored at 'public/uploads/thumb_bork.txt'
|
64
|
+
Given the file 'fixtures/monkey.txt' is stored at 'public/uploads/thumb_mini_bork.txt'
|
65
|
+
Given the file 'fixtures/monkey.txt' is stored at 'public/uploads/thumb_micro_bork.txt'
|
66
|
+
When I retrieve the file 'bork.txt' from the store
|
67
|
+
Then the uploader should have the url '/uploads/bork.txt'
|
68
|
+
And the uploader's version 'thumb' should have the url '/uploads/thumb_bork.txt'
|
69
|
+
And the uploader's nested version 'mini' nested in 'thumb' should have the url '/uploads/thumb_mini_bork.txt'
|
70
|
+
And the uploader's nested version 'micro' nested in 'thumb' should have the url '/uploads/thumb_micro_bork.txt'
|
@@ -0,0 +1,51 @@
|
|
1
|
+
Feature: uploader with file storage and overriden filename
|
2
|
+
In order to customize the filaname of uploaded files
|
3
|
+
As a developer using CarrierWave
|
4
|
+
I want to upload files to the filesystem with an overriden filename and different verions
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given an uploader class that uses the 'file' storage
|
8
|
+
And that the uploader class has a version named 'thumb'
|
9
|
+
And that the uploader has the filename overridden to 'grark.png'
|
10
|
+
And an instance of that class
|
11
|
+
|
12
|
+
Scenario: store a file
|
13
|
+
When I store the file 'fixtures/bork.txt'
|
14
|
+
Then there should be a file at 'public/uploads/grark.png'
|
15
|
+
Then there should be a file at 'public/uploads/thumb_grark.png'
|
16
|
+
And the file at 'public/uploads/grark.png' should be identical to the file at 'fixtures/bork.txt'
|
17
|
+
And the file at 'public/uploads/thumb_grark.png' should be identical to the file at 'fixtures/bork.txt'
|
18
|
+
And the uploader should have the url '/uploads/grark.png'
|
19
|
+
And the uploader's version 'thumb' should have the url '/uploads/thumb_grark.png'
|
20
|
+
|
21
|
+
Scenario: cache a file and then store it
|
22
|
+
When I cache the file 'fixtures/bork.txt'
|
23
|
+
Then there should be a file called 'bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
|
24
|
+
Then there should be a file called 'thumb_bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
|
25
|
+
And the file called 'bork.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/bork.txt'
|
26
|
+
And there should not be a file at 'public/uploads/grark.png'
|
27
|
+
And there should not be a file at 'public/uploads/thumb_grark.png'
|
28
|
+
When I store the file
|
29
|
+
Then there should be a file at 'public/uploads/grark.png'
|
30
|
+
And there should be a file at 'public/uploads/thumb_grark.png'
|
31
|
+
And the file at 'public/uploads/grark.png' should be identical to the file at 'fixtures/bork.txt'
|
32
|
+
And the file at 'public/uploads/thumb_grark.png' should be identical to the file at 'fixtures/bork.txt'
|
33
|
+
And the uploader should have the url '/uploads/grark.png'
|
34
|
+
And the uploader's version 'thumb' should have the url '/uploads/thumb_grark.png'
|
35
|
+
|
36
|
+
Scenario: retrieving a file from cache then storing
|
37
|
+
Given the file 'fixtures/bork.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/bork.txt'
|
38
|
+
Given the file 'fixtures/monkey.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/thumb_bork.txt'
|
39
|
+
When I retrieve the cache name '20090212-2343-8336-0348/bork.txt' from the cache
|
40
|
+
And I store the file
|
41
|
+
Then there should be a file at 'public/uploads/grark.png'
|
42
|
+
Then there should be a file at 'public/uploads/thumb_grark.png'
|
43
|
+
And the file at 'public/uploads/grark.png' should be identical to the file at 'fixtures/bork.txt'
|
44
|
+
And the file at 'public/uploads/thumb_grark.png' should be identical to the file at 'fixtures/monkey.txt'
|
45
|
+
|
46
|
+
Scenario: retrieving a file from store
|
47
|
+
Given the file 'fixtures/bork.txt' is stored at 'public/uploads/bork.txt'
|
48
|
+
Given the file 'fixtures/monkey.txt' is stored at 'public/uploads/thumb_bork.txt'
|
49
|
+
When I retrieve the file 'bork.txt' from the store
|
50
|
+
Then the uploader should have the url '/uploads/bork.txt'
|
51
|
+
And the uploader's version 'thumb' should have the url '/uploads/thumb_bork.txt'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
Feature: uploader with file storage and versions with overridden store dir
|
2
|
+
In order to be awesome
|
3
|
+
As a developer using CarrierWave
|
4
|
+
I want to upload files to the filesystem
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given an uploader class that uses the 'file' storage
|
8
|
+
And that the uploader class has a version named 'thumb'
|
9
|
+
And that the version 'thumb' has the store_dir overridden to 'public/monkey/llama'
|
10
|
+
And an instance of that class
|
11
|
+
|
12
|
+
Scenario: store a file
|
13
|
+
When I store the file 'fixtures/bork.txt'
|
14
|
+
Then there should be a file at 'public/uploads/bork.txt'
|
15
|
+
Then there should be a file at 'public/monkey/llama/thumb_bork.txt'
|
16
|
+
And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
17
|
+
And the file at 'public/monkey/llama/thumb_bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
18
|
+
|
19
|
+
Scenario: cache a file and then store it
|
20
|
+
When I cache the file 'fixtures/bork.txt'
|
21
|
+
Then there should be a file called 'bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
|
22
|
+
Then there should be a file called 'thumb_bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
|
23
|
+
And the file called 'bork.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/bork.txt'
|
24
|
+
And the file called 'thumb_bork.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/bork.txt'
|
25
|
+
And there should not be a file at 'public/uploads/bork.txt'
|
26
|
+
And there should not be a file at 'public/monkey/llama/thumb_bork.txt'
|
27
|
+
When I store the file
|
28
|
+
Then there should be a file at 'public/uploads/bork.txt'
|
29
|
+
Then there should be a file at 'public/monkey/llama/thumb_bork.txt'
|
30
|
+
And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
31
|
+
And the file at 'public/monkey/llama/thumb_bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
32
|
+
|
33
|
+
Scenario: retrieving a file from cache then storing
|
34
|
+
Given the file 'fixtures/bork.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/bork.txt'
|
35
|
+
Given the file 'fixtures/monkey.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/thumb_bork.txt'
|
36
|
+
When I retrieve the cache name '20090212-2343-8336-0348/bork.txt' from the cache
|
37
|
+
And I store the file
|
38
|
+
Then there should be a file at 'public/uploads/bork.txt'
|
39
|
+
Then there should be a file at 'public/monkey/llama/thumb_bork.txt'
|
40
|
+
And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
|
41
|
+
And the file at 'public/monkey/llama/thumb_bork.txt' should be identical to the file at 'fixtures/monkey.txt'
|
data/lib/carrierwave.rb
CHANGED
@@ -6,6 +6,9 @@ require 'carrierwave/core_ext/module_setup'
|
|
6
6
|
require 'carrierwave/core_ext/inheritable_attributes'
|
7
7
|
|
8
8
|
module CarrierWave
|
9
|
+
|
10
|
+
VERSION = "0.3.3"
|
11
|
+
|
9
12
|
class << self
|
10
13
|
attr_accessor :config, :logger
|
11
14
|
|
@@ -135,3 +138,8 @@ elsif defined?(Sinatra)
|
|
135
138
|
CarrierWave.config[:public] = Sinatra::Application.public
|
136
139
|
|
137
140
|
end
|
141
|
+
|
142
|
+
# MongoMapper is framework agnostic so we could need this in any environment.
|
143
|
+
if defined?(MongoMapper)
|
144
|
+
require File.join(File.dirname(__FILE__), "carrierwave", "orm", "mongomapper")
|
145
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'mongomapper'
|
3
|
+
|
4
|
+
module CarrierWave
|
5
|
+
module MongoMapper
|
6
|
+
include CarrierWave::Mount
|
7
|
+
##
|
8
|
+
# See +CarrierWave::Mount#mount_uploader+ for documentation
|
9
|
+
#
|
10
|
+
def mount_uploader(column, uploader, options={}, &block)
|
11
|
+
# We need to set the mount_on column (or key in MongoMapper's case)
|
12
|
+
# since MongoMapper will attempt to set the filename on
|
13
|
+
# the uploader instead of the file on a Document's initialization.
|
14
|
+
options[:mount_on] ||= "#{column}_filename"
|
15
|
+
key options[:mount_on]
|
16
|
+
|
17
|
+
super
|
18
|
+
alias_method :read_uploader, :[]
|
19
|
+
alias_method :write_uploader, :[]=
|
20
|
+
after_save "store_#{column}!".to_sym
|
21
|
+
before_save "write_#{column}_identifier".to_sym
|
22
|
+
after_destroy "remove_#{column}!".to_sym
|
23
|
+
end
|
24
|
+
end # MongoMapper
|
25
|
+
end # CarrierWave
|
26
|
+
|
27
|
+
MongoMapper::Document::ClassMethods.send(:include, CarrierWave::MongoMapper)
|
@@ -14,19 +14,19 @@ module CarrierWave
|
|
14
14
|
def initialize(uploader)
|
15
15
|
@uploader = uploader
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def self.setup!; end
|
19
|
-
|
19
|
+
|
20
20
|
def identifier
|
21
21
|
uploader.filename
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def store!(file)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def retrieve!(identifier)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
end # Abstract
|
31
31
|
end # Storage
|
32
32
|
end # CarrierWave
|
@@ -29,6 +29,18 @@ module CarrierWave
|
|
29
29
|
#
|
30
30
|
# The default is :public_read, it should work in most cases.
|
31
31
|
#
|
32
|
+
# You can change the generated url to a cnamed domain by setting the cnamed config:
|
33
|
+
#
|
34
|
+
# CarrierWave.config[:s3][:cnamed] = true
|
35
|
+
#
|
36
|
+
# No the resulting url will be
|
37
|
+
#
|
38
|
+
# http://bucket_name.domain.tld/path/to/file
|
39
|
+
#
|
40
|
+
# instead of
|
41
|
+
#
|
42
|
+
# http://s3.amazonaws.com/bucket_name.domain.tld/path/to/file
|
43
|
+
#
|
32
44
|
class S3 < Abstract
|
33
45
|
|
34
46
|
class File
|
@@ -86,7 +98,11 @@ module CarrierWave
|
|
86
98
|
# [String] file's url
|
87
99
|
#
|
88
100
|
def url
|
89
|
-
[
|
101
|
+
if CarrierWave::config[:s3][:cnamed]
|
102
|
+
["http://", bucket, @path].compact.join('/')
|
103
|
+
else
|
104
|
+
["http://s3.amazonaws.com", bucket, @path].compact.join('/')
|
105
|
+
end
|
90
106
|
end
|
91
107
|
|
92
108
|
def about
|