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
03560dc1
Commit
03560dc1
authored
Jun 30, 2011
by
Mike Burns
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fog_patches' of
https://github.com/kickstarter/paperclip
parents
db11fca8
be08b80e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
31 deletions
+28
-31
lib/paperclip/storage/fog.rb
+12
-8
test/fog_test.rb
+16
-23
No files found.
lib/paperclip/storage/fog.rb
View file @
03560dc1
...
@@ -45,6 +45,7 @@ module Paperclip
...
@@ -45,6 +45,7 @@ module Paperclip
@fog_credentials
=
@options
[
:fog_credentials
]
@fog_credentials
=
@options
[
:fog_credentials
]
@fog_host
=
@options
[
:fog_host
]
@fog_host
=
@options
[
:fog_host
]
@fog_public
=
@options
[
:fog_public
]
@fog_public
=
@options
[
:fog_public
]
@fog_file
=
@options
[
:fog_file
]
||
{}
@url
=
':fog_public_url'
@url
=
':fog_public_url'
Paperclip
.
interpolates
(
:fog_public_url
)
do
|
attachment
,
style
|
Paperclip
.
interpolates
(
:fog_public_url
)
do
|
attachment
,
style
|
...
@@ -64,11 +65,19 @@ module Paperclip
...
@@ -64,11 +65,19 @@ module Paperclip
def
flush_writes
def
flush_writes
for
style
,
file
in
@queued_for_write
do
for
style
,
file
in
@queued_for_write
do
log
(
"saving
#{
path
(
style
)
}
"
)
log
(
"saving
#{
path
(
style
)
}
"
)
directory
.
files
.
create
(
retried
=
false
begin
directory
.
files
.
create
(
@fog_file
.
merge
(
:body
=>
file
,
:body
=>
file
,
:key
=>
path
(
style
),
:key
=>
path
(
style
),
:public
=>
@fog_public
:public
=>
@fog_public
)
))
rescue
Excon
::
Errors
::
NotFound
raise
if
retried
retried
=
true
directory
.
save
retry
end
end
end
@queued_for_write
=
{}
@queued_for_write
=
{}
end
end
...
@@ -115,12 +124,7 @@ module Paperclip
...
@@ -115,12 +124,7 @@ module Paperclip
end
end
def
directory
def
directory
@directory
||=
begin
@directory
||=
connection
.
directories
.
new
(
:key
=>
@fog_directory
)
connection
.
directories
.
get
(
@fog_directory
)
||
connection
.
directories
.
create
(
:key
=>
@fog_directory
,
:public
=>
@fog_public
)
end
end
end
end
end
...
...
test/fog_test.rb
View file @
03560dc1
...
@@ -16,15 +16,21 @@ class FogTest < Test::Unit::TestCase
...
@@ -16,15 +16,21 @@ class FogTest < Test::Unit::TestCase
}
}
@connection
=
Fog
::
Storage
.
new
(
@credentials
)
@connection
=
Fog
::
Storage
.
new
(
@credentials
)
@connection
.
directories
.
create
(
:key
=>
@fog_directory
)
rebuild_model
(
@options
=
{
:fog_directory
=>
@fog_directory
,
:fog_directory
=>
@fog_directory
,
:fog_credentials
=>
@credentials
,
:fog_credentials
=>
@credentials
,
:fog_host
=>
nil
,
:fog_host
=>
nil
,
:fog_public
=>
true
,
:fog_public
=>
true
,
:fog_file
=>
{
:cache_control
=>
1234
},
:path
=>
":attachment/:basename.:extension"
,
:path
=>
":attachment/:basename.:extension"
,
:storage
=>
:fog
:storage
=>
:fog
)
}
rebuild_model
(
@options
)
end
end
should
"be extended by the Fog module"
do
should
"be extended by the Fog module"
do
...
@@ -46,16 +52,17 @@ class FogTest < Test::Unit::TestCase
...
@@ -46,16 +52,17 @@ class FogTest < Test::Unit::TestCase
end
end
context
"without a bucket"
do
context
"without a bucket"
do
should
"succeed"
do
setup
do
@connection
.
directories
.
get
(
@fog_directory
).
destroy
end
should
"create the bucket"
do
assert
@dummy
.
save
assert
@dummy
.
save
assert
@connection
.
directories
.
get
(
@fog_directory
)
end
end
end
end
context
"with a bucket"
do
context
"with a bucket"
do
setup
do
@connection
.
directories
.
create
(
:key
=>
@fog_directory
)
end
should
"succeed"
do
should
"succeed"
do
assert
@dummy
.
save
assert
@dummy
.
save
end
end
...
@@ -63,14 +70,7 @@ class FogTest < Test::Unit::TestCase
...
@@ -63,14 +70,7 @@ class FogTest < Test::Unit::TestCase
context
"without a fog_host"
do
context
"without a fog_host"
do
setup
do
setup
do
rebuild_model
(
rebuild_model
(
@options
.
merge
(
:fog_host
=>
nil
))
:fog_directory
=>
@fog_directory
,
:fog_credentials
=>
@credentials
,
:fog_host
=>
nil
,
:fog_public
=>
true
,
:path
=>
":attachment/:basename.:extension"
,
:storage
=>
:fog
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
'.'
)
@dummy
.
avatar
=
StringIO
.
new
(
'.'
)
@dummy
.
save
@dummy
.
save
...
@@ -83,14 +83,7 @@ class FogTest < Test::Unit::TestCase
...
@@ -83,14 +83,7 @@ class FogTest < Test::Unit::TestCase
context
"with a fog_host"
do
context
"with a fog_host"
do
setup
do
setup
do
rebuild_model
(
rebuild_model
(
@options
.
merge
(
:fog_host
=>
'http://example.com'
))
:fog_directory
=>
@fog_directory
,
:fog_credentials
=>
@credentials
,
:fog_host
=>
'http://example.com'
,
:fog_public
=>
true
,
:path
=>
":attachment/:basename.:extension"
,
:storage
=>
:fog
)
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
StringIO
.
new
(
'.'
)
@dummy
.
avatar
=
StringIO
.
new
(
'.'
)
@dummy
.
save
@dummy
.
save
...
...
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