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
d687fca1
Commit
d687fca1
authored
Jan 25, 2013
by
Mike Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Push attachment definitions into a list of attachments for the rake task
parent
710f658c
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
9 deletions
+60
-9
lib/paperclip.rb
+1
-0
lib/paperclip/missing_attachment_styles.rb
+2
-1
lib/paperclip/tasks/attachments.rb
+35
-0
lib/tasks/paperclip.rake
+2
-0
test/tasks/attachments_test.rb
+20
-8
No files found.
lib/paperclip.rb
View file @
d687fca1
...
@@ -51,6 +51,7 @@ require 'paperclip/missing_attachment_styles'
...
@@ -51,6 +51,7 @@ require 'paperclip/missing_attachment_styles'
require
'paperclip/validators'
require
'paperclip/validators'
require
'paperclip/logger'
require
'paperclip/logger'
require
'paperclip/helpers'
require
'paperclip/helpers'
require
'paperclip/tasks/attachments'
require
'mime/types'
require
'mime/types'
require
'logger'
require
'logger'
require
'cocaine'
require
'cocaine'
...
...
lib/paperclip/missing_attachment_styles.rb
View file @
d687fca1
require
'paperclip/tasks/attachments'
require
'set'
require
'set'
module
Paperclip
module
Paperclip
class
<<
self
class
<<
self
attr_accessor
:classes_with_attachments
attr_accessor
:classes_with_attachments
...
...
lib/paperclip/tasks/attachments.rb
0 → 100644
View file @
d687fca1
require
'singleton'
module
Paperclip
module
Tasks
class
Attachments
include
Singleton
def
self
.
add
(
klass
,
attachment_name
,
attachment_options
)
instance
.
add
(
klass
,
attachment_name
,
attachment_options
)
end
def
self
.
names_for
(
klass
)
instance
.
names_for
(
klass
)
end
def
self
.
definitions_for
(
klass
)
instance
.
definitions_for
(
klass
)
end
def
add
(
klass
,
attachment_name
,
attachment_options
)
@attachments
||=
{}
@attachments
[
klass
]
||=
{}
@attachments
[
klass
][
attachment_name
]
=
attachment_options
end
def
names_for
(
klass
)
@attachments
[
klass
].
keys
end
def
definitions_for
(
klass
)
@attachments
[
klass
]
end
end
end
end
lib/tasks/paperclip.rake
View file @
d687fca1
require
'paperclip/tasks/attachments'
module
Paperclip
module
Paperclip
module
Task
module
Task
def
self
.
obtain_class
def
self
.
obtain_class
...
...
test/tasks/attachments_test.rb
View file @
d687fca1
...
@@ -4,23 +4,35 @@ require 'tasks/attachments'
...
@@ -4,23 +4,35 @@ require 'tasks/attachments'
class
AttachmentsTest
<
Test
::
Unit
::
TestCase
class
AttachmentsTest
<
Test
::
Unit
::
TestCase
context
'.names_for'
do
context
'.names_for'
do
should
'include attachment names for the given class'
do
should
'include attachment names for the given class'
do
F
oo
=
Class
.
new
f
oo
=
Class
.
new
Paperclip
::
Tasks
::
Attachments
.
add
(
F
oo
,
:avatar
,
{})
Paperclip
::
Tasks
::
Attachments
.
add
(
f
oo
,
:avatar
,
{})
assert_equal
[
:avatar
],
Paperclip
::
Tasks
::
Attachments
.
names_for
(
F
oo
)
assert_equal
[
:avatar
],
Paperclip
::
Tasks
::
Attachments
.
names_for
(
f
oo
)
end
end
should
'not include attachment names for other classes'
do
should
'not include attachment names for other classes'
do
F
oo
=
Class
.
new
f
oo
=
Class
.
new
B
ar
=
Class
.
new
b
ar
=
Class
.
new
Paperclip
::
Tasks
::
Attachments
.
add
(
F
oo
,
:avatar
,
{})
Paperclip
::
Tasks
::
Attachments
.
add
(
f
oo
,
:avatar
,
{})
Paperclip
::
Tasks
::
Attachments
.
add
(
B
ar
,
:lover
,
{})
Paperclip
::
Tasks
::
Attachments
.
add
(
b
ar
,
:lover
,
{})
assert_equal
[
:lover
],
Paperclip
::
Tasks
::
Attachments
.
names_for
(
B
ar
)
assert_equal
[
:lover
],
Paperclip
::
Tasks
::
Attachments
.
names_for
(
b
ar
)
end
end
end
end
context
'.definitions_for'
do
context
'.definitions_for'
do
should
'produce the attachment name and options'
do
expected_definitions
=
{
avatar:
{
yo:
'greeting'
},
greeter:
{
ciao:
'greeting'
}
}
foo
=
Class
.
new
Paperclip
::
Tasks
::
Attachments
.
add
(
foo
,
:avatar
,
{
yo:
'greeting'
})
Paperclip
::
Tasks
::
Attachments
.
add
(
foo
,
:greeter
,
{
ciao:
'greeting'
})
definitions
=
Paperclip
::
Tasks
::
Attachments
.
definitions_for
(
foo
)
assert_equal
expected_definitions
,
definitions
end
end
end
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