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
eadd4527
Commit
eadd4527
authored
Jul 10, 2012
by
Alan Ho
Committed by
Mike Burns
Sep 07, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce class-oriented programming to help metaclasses
parent
eb928346
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
2 deletions
+42
-2
lib/paperclip/instance_methods.rb
+2
-2
test/helper.rb
+7
-0
test/meta_class_test.rb
+33
-0
No files found.
lib/paperclip/instance_methods.rb
View file @
eadd4527
...
...
@@ -2,11 +2,11 @@ module Paperclip
module
InstanceMethods
#:nodoc:
def
attachment_for
name
@_paperclip_attachments
||=
{}
@_paperclip_attachments
[
name
]
||=
Attachment
.
new
(
name
,
self
,
self
.
class
.
attachment_definitions
[
name
])
@_paperclip_attachments
[
name
]
||=
Attachment
.
new
(
name
,
self
,
attachment_definitions
[
name
])
end
def
each_attachment
self
.
class
.
attachment_definitions
.
each
do
|
name
,
definition
|
self
.
attachment_definitions
.
each
do
|
name
,
definition
|
yield
(
name
,
attachment_for
(
name
))
end
end
...
...
test/helper.rb
View file @
eadd4527
...
...
@@ -103,6 +103,13 @@ def rebuild_class options = {}
end
end
def
rebuild_meta_class_of
obj
,
options
=
{}
(
class
<<
obj
;
self
;
end
).
tap
do
|
metaklass
|
metaklass
.
has_attached_file
:avatar
,
options
Paperclip
.
reset_duplicate_clash_check!
end
end
class
FakeModel
attr_accessor
:avatar_file_name
,
:avatar_file_size
,
...
...
test/meta_class_test.rb
0 → 100644
View file @
eadd4527
require
'./test/helper'
class
MetaClassTest
<
Test
::
Unit
::
TestCase
context
"A meta-class of dummy"
do
setup
do
rebuild_model
@file
=
File
.
new
(
fixture_file
(
"5k.png"
),
'rb'
)
end
teardown
{
@file
.
close
}
should
"be able to use Paperclip like a normal class"
do
reset_class
(
"Dummy"
)
@dummy
=
Dummy
.
new
assert_nothing_raised
do
rebuild_meta_class_of
(
@dummy
)
end
end
should
"work like any other instance"
do
reset_class
(
"Dummy"
)
@dummy
=
Dummy
.
new
rebuild_meta_class_of
(
@dummy
)
assert_nothing_raised
do
@dummy
.
avatar
=
@file
end
assert
@dummy
.
save
end
end
end
\ No newline at end of file
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