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
630c6341
Commit
630c6341
authored
Aug 30, 2011
by
Mike Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a Paperclip.register_processor configuration.
parent
6ced9eb3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
6 deletions
+50
-6
lib/paperclip.rb
+28
-6
test/paperclip_test.rb
+22
-0
No files found.
lib/paperclip.rb
View file @
630c6341
...
...
@@ -92,7 +92,7 @@ module Paperclip
# This method can log the command being run when
# Paperclip.options[:log_command] is set to true (defaults to false). This
# will only log if logging in general is set to true as well.
def
run
cmd
,
*
params
def
run
(
cmd
,
*
params
)
if
options
[
:image_magick_path
]
Paperclip
.
log
(
"[DEPRECATION] :image_magick_path is deprecated and will be removed. Use :command_path instead"
)
end
...
...
@@ -100,11 +100,16 @@ module Paperclip
Cocaine
::
CommandLine
.
new
(
cmd
,
*
params
).
run
end
def
processor
name
#:nodoc:
name
=
name
.
to_s
.
camelize
load_processor
(
name
)
unless
Paperclip
.
const_defined?
(
name
)
processor
=
Paperclip
.
const_get
(
name
)
processor
def
processor
(
name
)
#:nodoc:
@known_processors
||=
{}
if
@known_processors
[
name
.
to_s
]
@known_processors
[
name
.
to_s
]
else
name
=
name
.
to_s
.
camelize
load_processor
(
name
)
unless
Paperclip
.
const_defined?
(
name
)
processor
=
Paperclip
.
const_get
(
name
)
@known_processors
[
name
.
to_s
]
=
processor
end
end
def
load_processor
(
name
)
...
...
@@ -113,6 +118,23 @@ module Paperclip
end
end
def
clear_processors!
@known_processors
.
try
(
:clear
)
end
# You can add your own processor via the Paperclip configuration. Normally
# Paperclip will load all processors from the
# Rails.root/lib/paperclip_processors directory, but here you can add any
# existing class using this mechanism.
#
# Paperclip.configure do |c|
# c.register_processor :watermarker, WatermarkingProcessor.new
# end
def
register_processor
(
name
,
processor
)
@known_processors
||=
{}
@known_processors
[
name
.
to_s
]
=
processor
end
def
each_instance_with_attachment
(
klass
,
name
)
class_for
(
klass
).
all
.
each
do
|
instance
|
yield
(
instance
)
if
instance
.
send
(
:"
#{
name
}
?"
)
...
...
test/paperclip_test.rb
View file @
630c6341
...
...
@@ -272,4 +272,26 @@ class PaperclipTest < Test::Unit::TestCase
end
end
context
"configuring a custom processor"
do
setup
do
@freedom_processor
=
Class
.
new
do
def
make
(
file
,
options
=
{},
attachment
=
nil
)
file
end
end
.
new
Paperclip
.
configure
do
|
config
|
config
.
register_processor
(
:freedom
,
@freedom_processor
)
end
end
should
"be able to find the custom processor"
do
assert_equal
@freedom_processor
,
Paperclip
.
processor
(
:freedom
)
end
teardown
do
Paperclip
.
clear_processors!
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