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
710f658c
Commit
710f658c
authored
Jan 18, 2013
by
Mike Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: Paperclip::Tasks::Attachments
parent
40bdd3d5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
9 deletions
+39
-9
lib/paperclip.rb
+3
-0
lib/paperclip/missing_attachment_styles.rb
+1
-1
lib/tasks/paperclip.rake
+9
-3
test/paperclip_test.rb
+0
-5
test/tasks/attachments_test.rb
+26
-0
No files found.
lib/paperclip.rb
View file @
710f658c
...
...
@@ -180,6 +180,7 @@ module Paperclip
options
=
attachment_definitions
[
name
]
=
Paperclip
::
AttachmentOptions
.
new
(
options
)
Paperclip
.
classes_with_attachments
<<
self
.
name
Paperclip
.
check_for_path_clash
(
name
,
options
[
:path
],
self
.
name
)
after_save
{
send
(
name
).
send
(
:save
)
}
before_destroy
{
send
(
name
).
send
(
:queue_all_for_delete
)
}
...
...
@@ -187,6 +188,8 @@ module Paperclip
define_paperclip_callbacks
:post_process
,
:"
#{
name
}
_post_process"
Paperclip
::
Tasks
::
Attachments
.
add
(
self
,
name
,
options
)
define_method
name
do
|*
args
|
ivar
=
"@attachment_
#{
name
}
"
attachment
=
instance_variable_get
(
ivar
)
...
...
lib/paperclip/missing_attachment_styles.rb
View file @
710f658c
...
...
@@ -38,7 +38,7 @@ module Paperclip
Hash
.
new
.
tap
do
|
current_styles
|
Paperclip
.
classes_with_attachments
.
each
do
|
klass_name
|
klass
=
Paperclip
.
class_for
(
klass_name
)
klass
.
attachment_definitions
.
each
do
|
attachment_name
,
attachment_attributes
|
Paperclip
::
Tasks
::
Attachments
.
definitions_for
(
klass
)
.
each
do
|
attachment_name
,
attachment_attributes
|
# TODO: is it even possible to take into account Procs?
next
if
attachment_attributes
[
:styles
].
kind_of?
(
Proc
)
attachment_attributes
[
:styles
].
try
(
:keys
).
try
(
:each
)
do
|
style_name
|
...
...
lib/tasks/paperclip.rake
View file @
710f658c
...
...
@@ -9,11 +9,17 @@ module Paperclip
def
self
.
obtain_attachments
(
klass
)
klass
=
Paperclip
.
class_for
(
klass
.
to_s
)
name
=
ENV
[
'ATTACHMENT'
]
||
ENV
[
'attachment'
]
raise
"Class
#{
klass
.
name
}
has no attachments specified"
unless
klass
.
respond_to?
(
:attachment_definitions
)
if
!
name
.
blank?
&&
klass
.
attachment_definitions
.
keys
.
map
(
&
:to_s
).
include?
(
name
.
to_s
)
attachment_names
=
Paperclip
::
Tasks
::
Attachments
.
names_for
(
klass
)
if
attachment_names
.
empty?
raise
"Class
#{
klass
.
name
}
has no attachments specified"
end
if
!
name
.
blank?
&&
attachment_names
.
map
(
&
:to_s
).
include?
(
name
.
to_s
)
[
name
]
else
klass
.
attachment_definitions
.
key
s
attachment_name
s
end
end
end
...
...
test/paperclip_test.rb
View file @
710f658c
...
...
@@ -159,11 +159,6 @@ class PaperclipTest < Test::Unit::TestCase
end
end
should
"be able to see the attachment definition from the subclass's class"
do
assert_equal
"tmp/:class/omg/:style.:extension"
,
SubDummy
.
attachment_definitions
[
:avatar
][
:path
]
end
teardown
do
SubDummy
.
delete_all
Object
.
send
(
:remove_const
,
"SubDummy"
)
rescue
nil
...
...
test/tasks/attachments_test.rb
0 → 100644
View file @
710f658c
require
'./test/helper'
require
'tasks/attachments'
class
AttachmentsTest
<
Test
::
Unit
::
TestCase
context
'.names_for'
do
should
'include attachment names for the given class'
do
Foo
=
Class
.
new
Paperclip
::
Tasks
::
Attachments
.
add
(
Foo
,
:avatar
,
{})
assert_equal
[
:avatar
],
Paperclip
::
Tasks
::
Attachments
.
names_for
(
Foo
)
end
should
'not include attachment names for other classes'
do
Foo
=
Class
.
new
Bar
=
Class
.
new
Paperclip
::
Tasks
::
Attachments
.
add
(
Foo
,
:avatar
,
{})
Paperclip
::
Tasks
::
Attachments
.
add
(
Bar
,
:lover
,
{})
assert_equal
[
:lover
],
Paperclip
::
Tasks
::
Attachments
.
names_for
(
Bar
)
end
end
context
'.definitions_for'
do
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