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
f7a5b91b
Commit
f7a5b91b
authored
Jun 30, 2011
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Put the helper methods into Paperclip::Task module
Closes #434
parent
ff3929ee
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
9 deletions
+13
-9
lib/tasks/paperclip.rake
+13
-9
No files found.
lib/tasks/paperclip.rake
View file @
f7a5b91b
def
obtain_class
module
Paperclip
module
Task
def
self
.
obtain_class
class_name
=
ENV
[
'CLASS'
]
||
ENV
[
'class'
]
class_name
=
ENV
[
'CLASS'
]
||
ENV
[
'class'
]
raise
"Must specify CLASS"
unless
class_name
raise
"Must specify CLASS"
unless
class_name
class_name
class_name
end
end
def
obtain_attachments
(
klass
)
def
self
.
obtain_attachments
(
klass
)
klass
=
Paperclip
.
class_for
(
klass
.
to_s
)
klass
=
Paperclip
.
class_for
(
klass
.
to_s
)
name
=
ENV
[
'ATTACHMENT'
]
||
ENV
[
'attachment'
]
name
=
ENV
[
'ATTACHMENT'
]
||
ENV
[
'attachment'
]
raise
"Class
#{
klass
.
name
}
has no attachments specified"
unless
klass
.
respond_to?
(
:attachment_definitions
)
raise
"Class
#{
klass
.
name
}
has no attachments specified"
unless
klass
.
respond_to?
(
:attachment_definitions
)
...
@@ -13,6 +15,8 @@ def obtain_attachments(klass)
...
@@ -13,6 +15,8 @@ def obtain_attachments(klass)
else
else
klass
.
attachment_definitions
.
keys
klass
.
attachment_definitions
.
keys
end
end
end
end
end
end
namespace
:paperclip
do
namespace
:paperclip
do
...
@@ -23,8 +27,8 @@ namespace :paperclip do
...
@@ -23,8 +27,8 @@ namespace :paperclip do
desc
"Regenerates thumbnails for a given CLASS (and optional ATTACHMENT and STYLES splitted by comma)."
desc
"Regenerates thumbnails for a given CLASS (and optional ATTACHMENT and STYLES splitted by comma)."
task
:thumbnails
=>
:environment
do
task
:thumbnails
=>
:environment
do
errors
=
[]
errors
=
[]
klass
=
obtain_class
klass
=
Paperclip
::
Task
.
obtain_class
names
=
obtain_attachments
(
klass
)
names
=
Paperclip
::
Task
.
obtain_attachments
(
klass
)
styles
=
(
ENV
[
'STYLES'
]
||
ENV
[
'styles'
]
||
''
).
split
(
','
).
map
(
&
:to_sym
)
styles
=
(
ENV
[
'STYLES'
]
||
ENV
[
'styles'
]
||
''
).
split
(
','
).
map
(
&
:to_sym
)
names
.
each
do
|
name
|
names
.
each
do
|
name
|
Paperclip
.
each_instance_with_attachment
(
klass
,
name
)
do
|
instance
|
Paperclip
.
each_instance_with_attachment
(
klass
,
name
)
do
|
instance
|
...
@@ -37,8 +41,8 @@ namespace :paperclip do
...
@@ -37,8 +41,8 @@ namespace :paperclip do
desc
"Regenerates content_type/size metadata for a given CLASS (and optional ATTACHMENT)."
desc
"Regenerates content_type/size metadata for a given CLASS (and optional ATTACHMENT)."
task
:metadata
=>
:environment
do
task
:metadata
=>
:environment
do
klass
=
obtain_class
klass
=
Paperclip
::
Task
.
obtain_class
names
=
obtain_attachments
(
klass
)
names
=
Paperclip
::
Task
.
obtain_attachments
(
klass
)
names
.
each
do
|
name
|
names
.
each
do
|
name
|
Paperclip
.
each_instance_with_attachment
(
klass
,
name
)
do
|
instance
|
Paperclip
.
each_instance_with_attachment
(
klass
,
name
)
do
|
instance
|
if
file
=
instance
.
send
(
name
).
to_file
(
:original
)
if
file
=
instance
.
send
(
name
).
to_file
(
:original
)
...
@@ -60,8 +64,8 @@ namespace :paperclip do
...
@@ -60,8 +64,8 @@ namespace :paperclip do
desc
"Cleans out invalid attachments. Useful after you've added new validations."
desc
"Cleans out invalid attachments. Useful after you've added new validations."
task
:clean
=>
:environment
do
task
:clean
=>
:environment
do
klass
=
obtain_class
klass
=
Paperclip
::
Task
.
obtain_class
names
=
obtain_attachments
(
klass
)
names
=
Paperclip
::
Task
.
obtain_attachments
(
klass
)
names
.
each
do
|
name
|
names
.
each
do
|
name
|
Paperclip
.
each_instance_with_attachment
(
klass
,
name
)
do
|
instance
|
Paperclip
.
each_instance_with_attachment
(
klass
,
name
)
do
|
instance
|
instance
.
send
(
name
).
send
(
:validate
)
instance
.
send
(
name
).
send
(
:validate
)
...
...
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