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
02bd35fe
Commit
02bd35fe
authored
Jan 25, 2013
by
Mike Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pull the file setter into a separate object
parent
dad6086e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
11 deletions
+41
-11
lib/paperclip.rb
+9
-10
lib/paperclip/has_attached_file.rb
+14
-0
test/has_attached_file_test.rb
+17
-0
test/tasks/attachments_test.rb
+1
-1
No files found.
lib/paperclip.rb
View file @
02bd35fe
...
...
@@ -51,6 +51,7 @@ require 'paperclip/missing_attachment_styles'
require
'paperclip/validators'
require
'paperclip/logger'
require
'paperclip/helpers'
require
'paperclip/has_attached_file'
require
'paperclip/tasks/attachments'
require
'mime/types'
require
'logger'
...
...
@@ -173,17 +174,24 @@ module Paperclip
# end
# end
def
has_attached_file
(
name
,
options
=
{})
HasAttachedFile
.
new
(
name
,
options
).
define_on
(
self
)
options
=
Paperclip
::
AttachmentOptions
.
new
(
options
)
Paperclip
.
classes_with_attachments
<<
self
.
name
Paperclip
.
check_for_path_clash
(
name
,
options
[
:path
],
self
.
name
)
Paperclip
::
Tasks
::
Attachments
.
add
(
self
,
name
,
options
)
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"
Paperclip
::
Tasks
::
Attachments
.
add
(
self
,
name
,
options
)
validates_each
(
name
)
do
|
record
,
attr
,
value
|
attachment
=
record
.
send
(
name
)
attachment
.
send
(
:flush_errors
)
end
define_method
name
do
|*
args
|
ivar
=
"@attachment_
#{
name
}
"
...
...
@@ -201,18 +209,9 @@ module Paperclip
end
end
define_method
"
#{
name
}
="
do
|
file
|
send
(
name
).
assign
(
file
)
end
define_method
"
#{
name
}
?"
do
send
(
name
).
file?
end
validates_each
(
name
)
do
|
record
,
attr
,
value
|
attachment
=
record
.
send
(
name
)
attachment
.
send
(
:flush_errors
)
end
end
end
end
...
...
lib/paperclip/has_attached_file.rb
0 → 100644
View file @
02bd35fe
module
Paperclip
class
HasAttachedFile
def
initialize
(
name
,
options
)
@name
=
name
end
def
define_on
(
klass
)
name
=
@name
klass
.
send
:define_method
,
"
#{
@name
}
="
do
|
file
|
send
(
name
).
assign
(
file
)
end
end
end
end
test/has_attached_file_test.rb
0 → 100644
View file @
02bd35fe
require
'./test/helper'
require
'paperclip/has_attached_file'
class
HasAttachedFileTest
<
Test
::
Unit
::
TestCase
context
'#define_on'
do
should
'define a setter on the class object'
do
a_class
=
stub
(
'class'
,
define_method:
nil
)
has_attached_file
=
Paperclip
::
HasAttachedFile
.
new
(
:avatar
,
{})
has_attached_file
.
define_on
(
a_class
)
assert_received
(
a_class
,
:define_method
)
do
|
expect
|
expect
.
with
(
'avatar='
)
end
end
end
end
test/tasks/attachments_test.rb
View file @
02bd35fe
require
'./test/helper'
require
'tasks/attachments'
require
'
paperclip/
tasks/attachments'
class
AttachmentsTest
<
Test
::
Unit
::
TestCase
context
'.names_for'
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