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
10968ea3
Commit
10968ea3
authored
Jul 29, 2008
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added logging to paperclip.rb and attachment.rb
parent
2ff75d11
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
0 deletions
+22
-0
lib/paperclip/attachment.rb
+12
-0
lib/paperclip/storage.rb
+9
-0
test/attachment_test.rb
+1
-0
No files found.
lib/paperclip/attachment.rb
View file @
10968ea3
...
@@ -43,6 +43,8 @@ module Paperclip
...
@@ -43,6 +43,8 @@ module Paperclip
normalize_style_definition
normalize_style_definition
initialize_storage
initialize_storage
logger
.
info
(
"[paperclip] Paperclip attachment
#{
name
}
on
#{
instance
.
class
}
initialized."
)
end
end
# What gets called when you call instance.attachment = File. It clears errors,
# What gets called when you call instance.attachment = File. It clears errors,
...
@@ -50,6 +52,7 @@ module Paperclip
...
@@ -50,6 +52,7 @@ module Paperclip
# the previous file for deletion, to be flushed away on #save of its host.
# the previous file for deletion, to be flushed away on #save of its host.
def
assign
uploaded_file
def
assign
uploaded_file
return
nil
unless
valid_assignment?
(
uploaded_file
)
return
nil
unless
valid_assignment?
(
uploaded_file
)
logger
.
info
(
"[paperclip] Assigning
#{
uploaded_file
}
to
#{
name
}
"
)
queue_existing_for_delete
queue_existing_for_delete
@errors
=
[]
@errors
=
[]
...
@@ -57,6 +60,7 @@ module Paperclip
...
@@ -57,6 +60,7 @@ module Paperclip
return
nil
if
uploaded_file
.
nil?
return
nil
if
uploaded_file
.
nil?
logger
.
info
(
"[paperclip] Writing attributes for
#{
name
}
"
)
@queued_for_write
[
:original
]
=
uploaded_file
.
to_tempfile
@queued_for_write
[
:original
]
=
uploaded_file
.
to_tempfile
@instance
[
:"
#{
@name
}
_file_name"
]
=
uploaded_file
.
original_filename
.
strip
.
gsub
/[^\w\d\.\-]+/
,
'_'
@instance
[
:"
#{
@name
}
_file_name"
]
=
uploaded_file
.
original_filename
.
strip
.
gsub
/[^\w\d\.\-]+/
,
'_'
@instance
[
:"
#{
@name
}
_content_type"
]
=
uploaded_file
.
content_type
.
strip
@instance
[
:"
#{
@name
}
_content_type"
]
=
uploaded_file
.
content_type
.
strip
...
@@ -111,11 +115,13 @@ module Paperclip
...
@@ -111,11 +115,13 @@ module Paperclip
# the instance's errors and returns false, cancelling the save.
# the instance's errors and returns false, cancelling the save.
def
save
def
save
if
valid?
if
valid?
logger
.
info
(
"[paperclip] Saving files for
#{
name
}
"
)
flush_deletes
flush_deletes
flush_writes
flush_writes
@dirty
=
false
@dirty
=
false
true
true
else
else
logger
.
info
(
"[paperclip] Errors on
#{
name
}
. Not saving."
)
flush_errors
flush_errors
false
false
end
end
...
@@ -173,6 +179,10 @@ module Paperclip
...
@@ -173,6 +179,10 @@ module Paperclip
private
private
def
logger
instance
.
logger
end
def
valid_assignment?
file
#:nodoc:
def
valid_assignment?
file
#:nodoc:
file
.
nil?
||
(
file
.
respond_to?
(
:original_filename
)
&&
file
.
respond_to?
(
:content_type
))
file
.
nil?
||
(
file
.
respond_to?
(
:original_filename
)
&&
file
.
respond_to?
(
:content_type
))
end
end
...
@@ -202,6 +212,7 @@ module Paperclip
...
@@ -202,6 +212,7 @@ module Paperclip
def
post_process
#:nodoc:
def
post_process
#:nodoc:
return
if
@queued_for_write
[
:original
].
nil?
return
if
@queued_for_write
[
:original
].
nil?
logger
.
info
(
"[paperclip] Post-processing
#{
name
}
"
)
@styles
.
each
do
|
name
,
args
|
@styles
.
each
do
|
name
,
args
|
begin
begin
dimensions
,
format
=
args
dimensions
,
format
=
args
...
@@ -228,6 +239,7 @@ module Paperclip
...
@@ -228,6 +239,7 @@ module Paperclip
def
queue_existing_for_delete
#:nodoc:
def
queue_existing_for_delete
#:nodoc:
return
if
original_filename
.
blank?
return
if
original_filename
.
blank?
logger
.
info
(
"[paperclip] Queueing the existing files for
#{
name
}
for deletion."
)
@queued_for_delete
+=
[
:original
,
*
@styles
.
keys
].
uniq
.
map
do
|
style
|
@queued_for_delete
+=
[
:original
,
*
@styles
.
keys
].
uniq
.
map
do
|
style
|
path
(
style
)
if
exists?
(
style
)
path
(
style
)
if
exists?
(
style
)
end
.
compact
end
.
compact
...
...
lib/paperclip/storage.rb
View file @
10968ea3
...
@@ -36,8 +36,10 @@ module Paperclip
...
@@ -36,8 +36,10 @@ module Paperclip
alias_method
:to_io
,
:to_file
alias_method
:to_io
,
:to_file
def
flush_writes
#:nodoc:
def
flush_writes
#:nodoc:
logger
.
info
(
"[paperclip] Writing files for
#{
name
}
"
)
@queued_for_write
.
each
do
|
style
,
file
|
@queued_for_write
.
each
do
|
style
,
file
|
FileUtils
.
mkdir_p
(
File
.
dirname
(
path
(
style
)))
FileUtils
.
mkdir_p
(
File
.
dirname
(
path
(
style
)))
logger
.
info
(
"[paperclip] ->
#{
path
(
style
)
}
"
)
result
=
file
.
stream_to
(
path
(
style
))
result
=
file
.
stream_to
(
path
(
style
))
file
.
close
file
.
close
result
.
close
result
.
close
...
@@ -46,8 +48,10 @@ module Paperclip
...
@@ -46,8 +48,10 @@ module Paperclip
end
end
def
flush_deletes
#:nodoc:
def
flush_deletes
#:nodoc:
logger
.
info
(
"[paperclip] Deleting files for
#{
name
}
"
)
@queued_for_delete
.
each
do
|
path
|
@queued_for_delete
.
each
do
|
path
|
begin
begin
logger
.
info
(
"[paperclip] ->
#{
path
}
"
)
FileUtils
.
rm
(
path
)
if
File
.
exist?
(
path
)
FileUtils
.
rm
(
path
)
if
File
.
exist?
(
path
)
rescue
Errno
::
ENOENT
=>
e
rescue
Errno
::
ENOENT
=>
e
# ignore file-not-found, let everything else pass
# ignore file-not-found, let everything else pass
...
@@ -102,6 +106,7 @@ module Paperclip
...
@@ -102,6 +106,7 @@ module Paperclip
base
.
class
.
interpolations
[
:s3_url
]
=
lambda
do
|
attachment
,
style
|
base
.
class
.
interpolations
[
:s3_url
]
=
lambda
do
|
attachment
,
style
|
"https://s3.amazonaws.com/
#{
attachment
.
bucket_name
}
/
#{
attachment
.
path
(
style
).
gsub
(
%r{^/}
,
""
)
}
"
"https://s3.amazonaws.com/
#{
attachment
.
bucket_name
}
/
#{
attachment
.
path
(
style
).
gsub
(
%r{^/}
,
""
)
}
"
end
end
ActiveRecord
::
Base
.
logger
.
info
(
"[paperclip] S3 Storage Initalized."
)
end
end
def
s3
def
s3
...
@@ -135,8 +140,10 @@ module Paperclip
...
@@ -135,8 +140,10 @@ module Paperclip
alias_method
:to_io
,
:to_file
alias_method
:to_io
,
:to_file
def
flush_writes
#:nodoc:
def
flush_writes
#:nodoc:
logger
.
info
(
"[paperclip] Writing files for
#{
name
}
"
)
@queued_for_write
.
each
do
|
style
,
file
|
@queued_for_write
.
each
do
|
style
,
file
|
begin
begin
logger
.
info
(
"[paperclip] ->
#{
path
(
style
)
}
"
)
key
=
s3_bucket
.
key
(
path
(
style
))
key
=
s3_bucket
.
key
(
path
(
style
))
key
.
data
=
file
key
.
data
=
file
key
.
put
(
nil
,
@s3_permissions
)
key
.
put
(
nil
,
@s3_permissions
)
...
@@ -148,8 +155,10 @@ module Paperclip
...
@@ -148,8 +155,10 @@ module Paperclip
end
end
def
flush_deletes
#:nodoc:
def
flush_deletes
#:nodoc:
logger
.
info
(
"[paperclip] Writing files for
#{
name
}
"
)
@queued_for_delete
.
each
do
|
path
|
@queued_for_delete
.
each
do
|
path
|
begin
begin
logger
.
info
(
"[paperclip] ->
#{
path
(
style
)
}
"
)
if
file
=
s3_bucket
.
key
(
path
)
if
file
=
s3_bucket
.
key
(
path
)
file
.
delete
file
.
delete
end
end
...
...
test/attachment_test.rb
View file @
10968ea3
...
@@ -154,6 +154,7 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -154,6 +154,7 @@ class AttachmentTest < Test::Unit::TestCase
@instance
.
stubs
(
:[]
).
with
(
:test_file_name
).
returns
(
nil
)
@instance
.
stubs
(
:[]
).
with
(
:test_file_name
).
returns
(
nil
)
@instance
.
stubs
(
:[]
).
with
(
:test_content_type
).
returns
(
nil
)
@instance
.
stubs
(
:[]
).
with
(
:test_content_type
).
returns
(
nil
)
@instance
.
stubs
(
:[]
).
with
(
:test_file_size
).
returns
(
nil
)
@instance
.
stubs
(
:[]
).
with
(
:test_file_size
).
returns
(
nil
)
@instance
.
stubs
(
:logger
).
returns
(
ActiveRecord
::
Base
.
logger
)
@attachment
=
Paperclip
::
Attachment
.
new
(
:test
,
@attachment
=
Paperclip
::
Attachment
.
new
(
:test
,
@instance
)
@instance
)
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
...
...
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