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
end
processor
end
def
log
message
logger
.
info
(
"[paperclip]
#{
message
}
"
)
if
logging?
end
def
logger
ActiveRecord
::
Base
.
logger
end
def
logging?
options
[
:log
]
end
end
class
PaperclipError
<
StandardError
#:nodoc:
...
...
lib/paperclip/attachment.rb
View file @
04140e5a
...
...
@@ -61,11 +61,7 @@ module Paperclip
# If the file that is assigned is not valid, the processing (i.e.
# thumbnailing, etc) will NOT be run.
def
assign
uploaded_file
%w(file_name)
.
each
do
|
field
|
unless
@instance
.
class
.
column_names
.
include?
(
"
#{
name
}
_
#{
field
}
"
)
raise
PaperclipError
.
new
(
"
#{
@instance
.
class
}
model does not have required column '
#{
name
}
_
#{
field
}
'"
)
end
end
ensure_required_accessors!
if
uploaded_file
.
is_a?
(
Paperclip
::
Attachment
)
uploaded_file
=
uploaded_file
.
to_file
(
:original
)
...
...
@@ -254,16 +250,16 @@ module Paperclip
private
def
logger
#:nodoc:
instance
.
logger
def
ensure_required_accessors!
%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
def
log
message
#:nodoc:
logger
.
info
(
"[paperclip]
#{
message
}
"
)
if
logging?
end
def
logging?
#:nodoc:
Paperclip
.
options
[
:log
]
Paperclip
.
log
(
message
)
end
def
valid_assignment?
file
#:nodoc:
...
...
lib/paperclip/storage.rb
View file @
04140e5a
...
...
@@ -39,7 +39,7 @@ module Paperclip
@queued_for_write
.
each
do
|
style
,
file
|
file
.
close
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
.
chmod
(
0644
,
path
(
style
))
end
...
...
@@ -49,7 +49,7 @@ module Paperclip
def
flush_deletes
#:nodoc:
@queued_for_delete
.
each
do
|
path
|
begin
log
ger
.
info
(
"[paperclip]
deleting
#{
path
}
"
)
log
(
"
deleting
#{
path
}
"
)
FileUtils
.
rm
(
path
)
if
File
.
exist?
(
path
)
rescue
Errno
::
ENOENT
=>
e
# ignore file-not-found, let everything else pass
...
...
@@ -62,7 +62,7 @@ module Paperclip
rescue
Errno
::
EEXIST
,
Errno
::
ENOTEMPTY
,
Errno
::
ENOENT
,
Errno
::
EINVAL
,
Errno
::
ENOTDIR
# Stop trying to remove parent directories
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
end
end
...
...
@@ -194,7 +194,7 @@ module Paperclip
def
flush_writes
#:nodoc:
@queued_for_write
.
each
do
|
style
,
file
|
begin
log
ger
.
info
(
"[paperclip]
saving
#{
path
(
style
)
}
"
)
log
(
"
saving
#{
path
(
style
)
}
"
)
key
=
s3_bucket
.
key
(
path
(
style
))
key
.
data
=
file
key
.
put
(
nil
,
@s3_permissions
,
{
'Content-type'
=>
instance_read
(
:content_type
)}.
merge
(
@s3_headers
))
...
...
@@ -208,7 +208,7 @@ module Paperclip
def
flush_deletes
#:nodoc:
@queued_for_delete
.
each
do
|
path
|
begin
log
ger
.
info
(
"[paperclip]
deleting
#{
path
}
"
)
log
(
"
deleting
#{
path
}
"
)
if
file
=
s3_bucket
.
key
(
path
)
file
.
delete
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