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
04140e5a
Commit
04140e5a
authored
May 08, 2009
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved logging aroud, extracted column checks, changed column check to attr_accessor check.
parent
1ef75b0b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
17 deletions
+25
-17
lib/paperclip.rb
+12
-0
lib/paperclip/attachment.rb
+8
-12
lib/paperclip/storage.rb
+5
-5
No files found.
lib/paperclip.rb
View file @
04140e5a
...
@@ -116,6 +116,18 @@ module Paperclip
...
@@ -116,6 +116,18 @@ module Paperclip
end
end
processor
processor
end
end
def
log
message
logger
.
info
(
"[paperclip]
#{
message
}
"
)
if
logging?
end
def
logger
ActiveRecord
::
Base
.
logger
end
def
logging?
options
[
:log
]
end
end
end
class
PaperclipError
<
StandardError
#:nodoc:
class
PaperclipError
<
StandardError
#:nodoc:
...
...
lib/paperclip/attachment.rb
View file @
04140e5a
...
@@ -61,11 +61,7 @@ module Paperclip
...
@@ -61,11 +61,7 @@ module Paperclip
# If the file that is assigned is not valid, the processing (i.e.
# If the file that is assigned is not valid, the processing (i.e.
# thumbnailing, etc) will NOT be run.
# thumbnailing, etc) will NOT be run.
def
assign
uploaded_file
def
assign
uploaded_file
%w(file_name)
.
each
do
|
field
|
ensure_required_accessors!
unless
@instance
.
class
.
column_names
.
include?
(
"
#{
name
}
_
#{
field
}
"
)
raise
PaperclipError
.
new
(
"
#{
@instance
.
class
}
model does not have required column '
#{
name
}
_
#{
field
}
'"
)
end
end
if
uploaded_file
.
is_a?
(
Paperclip
::
Attachment
)
if
uploaded_file
.
is_a?
(
Paperclip
::
Attachment
)
uploaded_file
=
uploaded_file
.
to_file
(
:original
)
uploaded_file
=
uploaded_file
.
to_file
(
:original
)
...
@@ -254,16 +250,16 @@ module Paperclip
...
@@ -254,16 +250,16 @@ module Paperclip
private
private
def
logger
#:nodoc:
def
ensure_required_accessors!
instance
.
logger
%w(file_name)
.
each
do
|
field
|
unless
@instance
.
respond_to?
(
"
#{
name
}
_
#{
field
}
"
)
&&
@instance
.
respond_to?
(
"
#{
name
}
_
#{
field
}
="
)
raise
PaperclipError
.
new
(
"
#{
@instance
.
class
}
model missing required attr_accessor for '
#{
name
}
_
#{
field
}
'"
)
end
end
end
end
def
log
message
#:nodoc:
def
log
message
#:nodoc:
logger
.
info
(
"[paperclip]
#{
message
}
"
)
if
logging?
Paperclip
.
log
(
message
)
end
def
logging?
#:nodoc:
Paperclip
.
options
[
:log
]
end
end
def
valid_assignment?
file
#:nodoc:
def
valid_assignment?
file
#:nodoc:
...
...
lib/paperclip/storage.rb
View file @
04140e5a
...
@@ -39,7 +39,7 @@ module Paperclip
...
@@ -39,7 +39,7 @@ module Paperclip
@queued_for_write
.
each
do
|
style
,
file
|
@queued_for_write
.
each
do
|
style
,
file
|
file
.
close
file
.
close
FileUtils
.
mkdir_p
(
File
.
dirname
(
path
(
style
)))
FileUtils
.
mkdir_p
(
File
.
dirname
(
path
(
style
)))
log
ger
.
info
(
"[paperclip]
saving
#{
path
(
style
)
}
"
)
log
(
"
saving
#{
path
(
style
)
}
"
)
FileUtils
.
mv
(
file
.
path
,
path
(
style
))
FileUtils
.
mv
(
file
.
path
,
path
(
style
))
FileUtils
.
chmod
(
0644
,
path
(
style
))
FileUtils
.
chmod
(
0644
,
path
(
style
))
end
end
...
@@ -49,7 +49,7 @@ module Paperclip
...
@@ -49,7 +49,7 @@ module Paperclip
def
flush_deletes
#:nodoc:
def
flush_deletes
#:nodoc:
@queued_for_delete
.
each
do
|
path
|
@queued_for_delete
.
each
do
|
path
|
begin
begin
log
ger
.
info
(
"[paperclip]
deleting
#{
path
}
"
)
log
(
"
deleting
#{
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
...
@@ -62,7 +62,7 @@ module Paperclip
...
@@ -62,7 +62,7 @@ module Paperclip
rescue
Errno
::
EEXIST
,
Errno
::
ENOTEMPTY
,
Errno
::
ENOENT
,
Errno
::
EINVAL
,
Errno
::
ENOTDIR
rescue
Errno
::
EEXIST
,
Errno
::
ENOTEMPTY
,
Errno
::
ENOENT
,
Errno
::
EINVAL
,
Errno
::
ENOTDIR
# Stop trying to remove parent directories
# Stop trying to remove parent directories
rescue
SystemCallError
=>
e
rescue
SystemCallError
=>
e
log
ger
.
info
(
"[paperclip]
There was an unexpected error while deleting directories:
#{
e
.
class
}
"
)
log
(
"
There was an unexpected error while deleting directories:
#{
e
.
class
}
"
)
# Ignore it
# Ignore it
end
end
end
end
...
@@ -194,7 +194,7 @@ module Paperclip
...
@@ -194,7 +194,7 @@ module Paperclip
def
flush_writes
#:nodoc:
def
flush_writes
#:nodoc:
@queued_for_write
.
each
do
|
style
,
file
|
@queued_for_write
.
each
do
|
style
,
file
|
begin
begin
log
ger
.
info
(
"[paperclip]
saving
#{
path
(
style
)
}
"
)
log
(
"
saving
#{
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
,
{
'Content-type'
=>
instance_read
(
:content_type
)}.
merge
(
@s3_headers
))
key
.
put
(
nil
,
@s3_permissions
,
{
'Content-type'
=>
instance_read
(
:content_type
)}.
merge
(
@s3_headers
))
...
@@ -208,7 +208,7 @@ module Paperclip
...
@@ -208,7 +208,7 @@ module Paperclip
def
flush_deletes
#:nodoc:
def
flush_deletes
#:nodoc:
@queued_for_delete
.
each
do
|
path
|
@queued_for_delete
.
each
do
|
path
|
begin
begin
log
ger
.
info
(
"[paperclip]
deleting
#{
path
}
"
)
log
(
"
deleting
#{
path
}
"
)
if
file
=
s3_bucket
.
key
(
path
)
if
file
=
s3_bucket
.
key
(
path
)
file
.
delete
file
.
delete
end
end
...
...
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