Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
f033d952
Commit
f033d952
authored
Mar 23, 2011
by
Mikel Lindsaar
Committed by
Prem Sichanugrist
Jun 20, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow :s3_host_alias to be a proc for dynamic cdn generation
parent
4e6fac4c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
lib/paperclip/storage/s3.rb
+1
-0
test/storage_test.rb
+22
-0
No files found.
lib/paperclip/storage/s3.rb
View file @
f033d952
...
...
@@ -76,6 +76,7 @@ module Paperclip
@s3_protocol
=
@options
[
:s3_protocol
]
||
(
@s3_permissions
==
:public_read
?
'http'
:
'https'
)
@s3_headers
=
@options
[
:s3_headers
]
||
{}
@s3_host_alias
=
@options
[
:s3_host_alias
]
@s3_host_alias
=
@s3_host_alias
.
call
(
self
)
if
@s3_host_alias
.
is_a?
(
Proc
)
unless
@url
.
to_s
.
match
(
/^:s3.*url$/
)
@path
=
@path
.
gsub
(
/:url/
,
@url
)
@url
=
":s3_path_url"
...
...
test/storage_test.rb
View file @
f033d952
...
...
@@ -141,6 +141,28 @@ class StorageTest < Test::Unit::TestCase
end
end
context
"generating a url with a proc as the host alias"
do
setup
do
AWS
::
S3
::
Base
.
stubs
(
:establish_connection!
)
rebuild_model
:storage
=>
:s3
,
:s3_credentials
=>
{
:bucket
=>
"prod_bucket"
},
:s3_host_alias
=>
Proc
.
new
{
|
image
|
"cdn
#{
image
.
size
.
to_i
%
4
}
.example.com"
},
:path
=>
":attachment/:basename.:extension"
,
:url
=>
":s3_alias_url"
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
end
should
"return a url based on the host_alias"
do
assert_match
%r{^http://cdn0.example.com/avatars/stringio.txt}
,
@dummy
.
avatar
.
url
end
should
"still return the bucket name"
do
assert_equal
"prod_bucket"
,
@dummy
.
avatar
.
bucket_name
end
end
context
""
do
setup
do
AWS
::
S3
::
Base
.
stubs
(
:establish_connection!
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment