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
40bdd3d5
Commit
40bdd3d5
authored
Jan 18, 2013
by
Mike Burns and George Brocklehurst
Committed by
Mike Burns
Jun 14, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove the InstanceMethods and reduce class-level state
parent
1da9e4d6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
53 deletions
+22
-53
lib/paperclip.rb
+20
-12
lib/paperclip/instance_methods.rb
+0
-35
lib/paperclip/matchers/have_attached_file_matcher.rb
+1
-5
test/storage/s3_test.rb
+1
-1
No files found.
lib/paperclip.rb
View file @
40bdd3d5
...
...
@@ -49,7 +49,6 @@ require 'paperclip/glue'
require
'paperclip/errors'
require
'paperclip/missing_attachment_styles'
require
'paperclip/validators'
require
'paperclip/instance_methods'
require
'paperclip/logger'
require
'paperclip/helpers'
require
'mime/types'
...
...
@@ -173,38 +172,47 @@ module Paperclip
# end
# end
def
has_attached_file
(
name
,
options
=
{})
include
InstanceMethods
if
attachment_definitions
.
nil?
self
.
attachment_definitions
=
{}
else
self
.
attachment_definitions
=
self
.
attachment_definitions
.
dup
end
attachment_definitions
[
name
]
=
Paperclip
::
AttachmentOptions
.
new
(
options
)
options
=
attachment_definitions
[
name
]
=
Paperclip
::
AttachmentOptions
.
new
(
options
)
Paperclip
.
classes_with_attachments
<<
self
.
name
after_save
:save_attached_files
before_destroy
:prepare_for_destroy
after_destroy
:destroy_attached_files
after_save
{
send
(
name
).
send
(
:save
)
}
before_destroy
{
send
(
name
).
send
(
:queue_all_for_delete
)
}
after_destroy
{
send
(
name
).
send
(
:flush_deletes
)
}
define_paperclip_callbacks
:post_process
,
:"
#{
name
}
_post_process"
define_method
name
do
|*
args
|
a
=
attachment_for
(
name
)
(
args
.
length
>
0
)
?
a
.
to_s
(
args
.
first
)
:
a
ivar
=
"@attachment_
#{
name
}
"
attachment
=
instance_variable_get
(
ivar
)
if
attachment
.
nil?
attachment
=
Attachment
.
new
(
name
,
self
,
options
)
instance_variable_set
(
ivar
,
attachment
)
end
if
args
.
length
>
0
attachment
.
to_s
(
args
.
first
)
else
attachment
end
end
define_method
"
#{
name
}
="
do
|
file
|
attachment_for
(
name
).
assign
(
file
)
send
(
name
).
assign
(
file
)
end
define_method
"
#{
name
}
?"
do
attachment_for
(
name
).
file?
send
(
name
).
file?
end
validates_each
(
name
)
do
|
record
,
attr
,
value
|
attachment
=
record
.
attachment_for
(
name
)
attachment
=
record
.
send
(
name
)
attachment
.
send
(
:flush_errors
)
end
end
...
...
lib/paperclip/instance_methods.rb
deleted
100644 → 0
View file @
1da9e4d6
module
Paperclip
module
InstanceMethods
#:nodoc:
def
attachment_for
name
@_paperclip_attachments
||=
{}
@_paperclip_attachments
[
name
]
||=
Attachment
.
new
(
name
,
self
,
attachment_definitions
[
name
])
end
def
each_attachment
self
.
attachment_definitions
.
each
do
|
name
,
definition
|
yield
(
name
,
attachment_for
(
name
))
end
end
def
save_attached_files
Paperclip
.
log
(
"Saving attachments."
)
each_attachment
do
|
name
,
attachment
|
attachment
.
send
(
:save
)
end
end
def
destroy_attached_files
Paperclip
.
log
(
"Deleting attachments."
)
each_attachment
do
|
name
,
attachment
|
attachment
.
send
(
:flush_deletes
)
end
end
def
prepare_for_destroy
Paperclip
.
log
(
"Scheduling attachments for deletion."
)
each_attachment
do
|
name
,
attachment
|
attachment
.
send
(
:queue_all_for_delete
)
end
end
end
end
lib/paperclip/matchers/have_attached_file_matcher.rb
View file @
40bdd3d5
...
...
@@ -20,7 +20,7 @@ module Paperclip
def
matches?
subject
@subject
=
subject
@subject
=
@subject
.
class
unless
Class
===
@subject
responds?
&&
has_column?
&&
included?
responds?
&&
has_column?
end
def
failure_message
...
...
@@ -47,10 +47,6 @@ module Paperclip
def
has_column?
@subject
.
column_names
.
include?
(
"
#{
@attachment_name
}
_file_name"
)
end
def
included?
@subject
.
ancestors
.
include?
(
Paperclip
::
InstanceMethods
)
end
end
end
end
...
...
test/storage/s3_test.rb
View file @
40bdd3d5
...
...
@@ -709,7 +709,7 @@ class S3Test < Test::Unit::TestCase
setup
do
AWS
::
S3
::
S3Object
.
any_instance
.
stubs
(
:exists?
).
returns
(
true
)
AWS
::
S3
::
S3Object
.
any_instance
.
stubs
(
:delete
)
@dummy
.
destroy
_attached_files
@dummy
.
destroy
end
should
"succeed"
do
...
...
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