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
ad034bae
Commit
ad034bae
authored
Apr 20, 2011
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A bit of name refactoring
parent
525b2968
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
3 deletions
+8
-3
lib/paperclip.rb
+2
-2
lib/tasks/paperclip.rake
+1
-1
test/paperclip_test.rb
+5
-0
No files found.
lib/paperclip.rb
View file @
ad034bae
...
@@ -114,7 +114,7 @@ module Paperclip
...
@@ -114,7 +114,7 @@ module Paperclip
end
end
def
each_instance_with_attachment
(
klass
,
name
)
def
each_instance_with_attachment
(
klass
,
name
)
obtain_class_from_class_name
(
klass
).
all
.
each
do
|
instance
|
class_for
(
klass
).
all
.
each
do
|
instance
|
yield
(
instance
)
if
instance
.
send
(
:"
#{
name
}
?"
)
yield
(
instance
)
if
instance
.
send
(
:"
#{
name
}
?"
)
end
end
end
end
...
@@ -133,7 +133,7 @@ module Paperclip
...
@@ -133,7 +133,7 @@ module Paperclip
options
[
:log
]
options
[
:log
]
end
end
def
obtain_class_from_class_name
(
class_name
)
def
class_for
(
class_name
)
class_name
.
split
(
'::'
).
inject
(
Object
)
do
|
klass
,
partial_class_name
|
class_name
.
split
(
'::'
).
inject
(
Object
)
do
|
klass
,
partial_class_name
|
klass
.
const_get
(
partial_class_name
)
klass
.
const_get
(
partial_class_name
)
end
end
...
...
lib/tasks/paperclip.rake
View file @
ad034bae
...
@@ -5,7 +5,7 @@ def obtain_class
...
@@ -5,7 +5,7 @@ def obtain_class
end
end
def
obtain_attachments
(
klass
)
def
obtain_attachments
(
klass
)
klass
=
Paperclip
.
obtain_class_from_class_name
(
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
)
if
!
name
.
blank?
&&
klass
.
attachment_definitions
.
keys
.
include?
(
name
)
if
!
name
.
blank?
&&
klass
.
attachment_definitions
.
keys
.
include?
(
name
)
...
...
test/paperclip_test.rb
View file @
ad034bae
...
@@ -72,6 +72,11 @@ class PaperclipTest < Test::Unit::TestCase
...
@@ -72,6 +72,11 @@ class PaperclipTest < Test::Unit::TestCase
assert_equal
::
Paperclip
::
Thumbnail
,
Paperclip
.
processor
(
:thumbnail
)
assert_equal
::
Paperclip
::
Thumbnail
,
Paperclip
.
processor
(
:thumbnail
)
end
end
should
"get a class from a namespaced class name"
do
class
::
One
;
class
Two
;
end
;
end
assert_equal
::
One
::
Two
,
Paperclip
.
class_for
(
"One::Two"
)
end
context
"An ActiveRecord model with an 'avatar' attachment"
do
context
"An ActiveRecord model with an 'avatar' attachment"
do
setup
do
setup
do
rebuild_model
:path
=>
"tmp/:class/omg/:style.:extension"
rebuild_model
:path
=>
"tmp/:class/omg/:style.:extension"
...
...
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