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
87bd86cc
Commit
87bd86cc
authored
17 years ago
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolved mvanholstyn's open file fixes with current code
parent
f79dadce
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
7 additions
and
23 deletions
+7
-23
lib/paperclip/attachment.rb
+0
-0
lib/paperclip/storage.rb
+3
-3
tasks/paperclip_tasks.rake
+3
-2
test/test_attachment.rb
+0
-17
test/test_integration.rb
+1
-1
No files found.
lib/paperclip/attachment.rb
View file @
87bd86cc
This diff is collapsed.
Click to expand it.
lib/paperclip/storage.rb
View file @
87bd86cc
...
@@ -16,7 +16,7 @@ module Paperclip
...
@@ -16,7 +16,7 @@ module Paperclip
# Returns representation of the data of the file assigned to the given
# Returns representation of the data of the file assigned to the given
# style, in the format most representative of the current storage.
# style, in the format most representative of the current storage.
def
to_file
style
=
default_style
def
to_file
style
=
default_style
File
.
new
(
path
(
style
))
if
exists?
(
style
)
@queued_for_write
[
style
]
||
(
File
.
new
(
path
(
style
))
if
exists?
(
style
)
)
end
end
alias_method
:to_io
,
:to_file
alias_method
:to_io
,
:to_file
...
@@ -35,7 +35,7 @@ module Paperclip
...
@@ -35,7 +35,7 @@ module Paperclip
begin
begin
FileUtils
.
rm
(
path
)
if
File
.
exist?
(
path
)
FileUtils
.
rm
(
path
)
if
File
.
exist?
(
path
)
rescue
Errno
::
ENOENT
=>
e
rescue
Errno
::
ENOENT
=>
e
# ignore
them
# ignore
file-not-found, let everything else pass
end
end
end
end
@queued_for_delete
=
[]
@queued_for_delete
=
[]
...
@@ -74,7 +74,7 @@ module Paperclip
...
@@ -74,7 +74,7 @@ module Paperclip
# Returns representation of the data of the file assigned to the given
# Returns representation of the data of the file assigned to the given
# style, in the format most representative of the current storage.
# style, in the format most representative of the current storage.
def
to_file
style
=
default_style
def
to_file
style
=
default_style
@s3_bucket
.
key
(
path
(
style
))
@
queued_for_write
[
style
]
||
@
s3_bucket
.
key
(
path
(
style
))
end
end
alias_method
:to_io
,
:to_file
alias_method
:to_io
,
:to_file
...
...
This diff is collapsed.
Click to expand it.
tasks/paperclip_tasks.rake
View file @
87bd86cc
def
obtain_class
def
obtain_class
class_name
=
ENV
[
'CLASS'
]
||
ENV
[
'class'
]
class_name
=
ENV
[
'CLASS'
]
||
ENV
[
'class'
]
raise
"Must specify CLASS"
unless
class_name
@klass
=
Object
.
const_get
(
class_name
)
@klass
=
Object
.
const_get
(
class_name
)
end
end
def
obtain_attachments
def
obtain_attachments
name
=
ENV
[
'ATTACHMENT'
]
||
ENV
[
'attachment'
]
name
=
ENV
[
'ATTACHMENT'
]
||
ENV
[
'attachment'
]
raise
"Class
#{
@klass
.
name
}
has no attachments specified"
unless
@klass
.
respond_to?
(
:attachment_names
)
if
!
name
.
blank?
&&
@klass
.
attachment_names
.
include?
(
name
)
if
!
name
.
blank?
&&
@klass
.
attachment_names
.
include?
(
name
)
[
name
]
[
name
]
else
else
...
@@ -16,11 +18,10 @@ namespace :paperclip do
...
@@ -16,11 +18,10 @@ namespace :paperclip do
desc
"Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)"
desc
"Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)"
task
:refresh
=>
:environment
do
task
:refresh
=>
:environment
do
klass
=
obtain_class
klass
=
obtain_class
instances
=
klass
.
find
(
:all
)
names
=
obtain_attachments
names
=
obtain_attachments
puts
"Regenerating thumbnails for
#{
instances
.
length
}
instances of
#{
klass
.
name
}
:"
puts
"Regenerating thumbnails for
#{
instances
.
length
}
instances of
#{
klass
.
name
}
:"
instances
.
each
do
|
instance
|
klass
.
find
(
:all
)
.
each
do
|
instance
|
names
.
each
do
|
name
|
names
.
each
do
|
name
|
result
=
if
instance
.
send
(
"
#{
name
}
?"
)
result
=
if
instance
.
send
(
"
#{
name
}
?"
)
instance
.
send
(
name
).
send
(
"post_process"
)
instance
.
send
(
name
).
send
(
"post_process"
)
...
...
This diff is collapsed.
Click to expand it.
test/test_attachment.rb
View file @
87bd86cc
...
@@ -195,23 +195,6 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -195,23 +195,6 @@ class AttachmentTest < Test::Unit::TestCase
@existing_names
.
each
{
|
f
|
assert
!
File
.
exists?
(
f
)
}
@existing_names
.
each
{
|
f
|
assert
!
File
.
exists?
(
f
)
}
end
end
end
end
context
"and deleted"
do
setup
do
@existing_names
=
@attachment
.
styles
.
keys
.
collect
do
|
style
|
@attachment
.
path
(
style
)
end
@instance
.
expects
(
:[]=
).
with
(
:test_file_name
,
nil
)
@instance
.
expects
(
:[]=
).
with
(
:test_content_type
,
nil
)
@instance
.
expects
(
:[]=
).
with
(
:test_file_size
,
nil
)
@attachment
.
assign
nil
@attachment
.
save
end
should
"delete the files"
do
@existing_names
.
each
{
|
f
|
assert
!
File
.
exists?
(
f
)
}
end
end
end
end
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
test/test_integration.rb
View file @
87bd86cc
...
@@ -223,7 +223,7 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -223,7 +223,7 @@ class IntegrationTest < Test::Unit::TestCase
expected
=
@dummy
.
avatar
.
to_file
expected
=
@dummy
.
avatar
.
to_file
@dummy
.
avatar
=
"not a file"
@dummy
.
avatar
=
"not a file"
assert
@dummy
.
valid?
assert
@dummy
.
valid?
assert_equal
expected
,
@dummy
.
avatar
.
to_fil
e
assert_equal
expected
.
full_name
,
@dummy
.
avatar
.
to_file
.
full_nam
e
@dummy
.
avatar
=
@bad_file
@dummy
.
avatar
=
@bad_file
assert
!
@dummy
.
valid?
assert
!
@dummy
.
valid?
...
...
This diff is collapsed.
Click to expand it.
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