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
ff6e8485
Commit
ff6e8485
authored
Nov 05, 2008
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved to send instead of [], so no columns specifically required, only methods.
parent
f301de52
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
24 deletions
+32
-24
lib/paperclip.rb
+2
-2
lib/paperclip/attachment.rb
+20
-12
test/attachment_test.rb
+10
-10
No files found.
lib/paperclip.rb
View file @
ff6e8485
...
...
@@ -182,7 +182,7 @@ module Paperclip
options[:in] = (0..options[:less_than])
end
if attachment.file? && !options[:in].include?(
instance[:"
#{
name
}
_file_size"]
.to_i)
if attachment.file? && !options[:in].include?(
attachment.instance_read(:file_size)
.to_i)
min = options[:in].first
max = options[:in].last
...
...
@@ -223,7 +223,7 @@ module Paperclip
unless attachment.original_filename.blank?
unless options[:content_type].blank?
content_type =
instance[:"
#{
name
}
_content_type"]
content_type =
attachment.instance_read(:content_type)
unless valid_types.any?{|t| t === content_type }
options[:message] || "is not one of the allowed file types."
end
...
...
lib/paperclip/attachment.rb
View file @
ff6e8485
...
...
@@ -56,7 +56,7 @@ module Paperclip
def
assign
uploaded_file
%w(file_name)
.
each
do
|
field
|
unless
@instance
.
class
.
column_names
.
include?
(
"
#{
name
}
_
#{
field
}
"
)
raise
PaperclipError
.
new
(
"
#{
self
}
model does not have required column '
#{
name
}
_
#{
field
}
'"
)
raise
PaperclipError
.
new
(
"
#{
@instance
.
class
}
model does not have required column '
#{
name
}
_
#{
field
}
'"
)
end
end
...
...
@@ -75,17 +75,17 @@ module Paperclip
logger
.
info
(
"[paperclip] Writing attributes for
#{
name
}
"
)
@queued_for_write
[
:original
]
=
uploaded_file
.
to_tempfile
@instance
[
:"
#{
@name
}
_file_name"
]
=
uploaded_file
.
original_filename
.
strip
.
gsub
/[^\w\d\.\-]+/
,
'_'
@instance
[
:"
#{
@name
}
_content_type"
]
=
uploaded_file
.
content_type
.
strip
@instance
[
:"
#{
@name
}
_file_size"
]
=
uploaded_file
.
size
.
to_i
@instance
[
:"
#{
@name
}
_updated_at"
]
=
Time
.
now
instance_write
(
:file_name
,
uploaded_file
.
original_filename
.
strip
.
gsub
(
/[^\w\d\.\-]+/
,
'_'
))
instance_write
(
:content_type
,
uploaded_file
.
content_type
.
strip
)
instance_write
(
:file_size
,
uploaded_file
.
size
.
to_i
)
instance_write
(
:updated_at
,
Time
.
now
)
@dirty
=
true
post_process
# Reset the file size if the original file was reprocessed.
@instance
[
:"
#{
@name
}
_file_size"
]
=
uploaded_file
.
size
.
to_i
instance_write
(
:file_size
,
uploaded_file
.
size
.
to_i
)
ensure
validate
end
...
...
@@ -148,11 +148,11 @@ module Paperclip
# Returns the name of the file as originally assigned, and as lives in the
# <attachment>_file_name attribute of the model.
def
original_filename
instance
[
:"
#{
name
}
_file_name"
]
instance
_read
(
:file_name
)
end
def
updated_at
time
=
instance
[
:"
#{
name
}
_updated_at"
]
time
=
instance
_read
(
:updated_at
)
time
&&
time
.
to_i
end
...
...
@@ -209,6 +209,14 @@ module Paperclip
!
original_filename
.
blank?
end
def
instance_write
(
attr
,
value
)
instance
.
send
(
:"
#{
name
}
_
#{
attr
}
="
,
value
)
end
def
instance_read
(
attr
)
instance
.
send
(
:"
#{
name
}
_
#{
attr
}
"
)
end
private
def
logger
...
...
@@ -280,10 +288,10 @@ module Paperclip
@queued_for_delete
+=
[
:original
,
*
@styles
.
keys
].
uniq
.
map
do
|
style
|
path
(
style
)
if
exists?
(
style
)
end
.
compact
@instance
[
:"
#{
@name
}
_file_name"
]
=
nil
@instance
[
:"
#{
@name
}
_content_type"
]
=
nil
@instance
[
:"
#{
@name
}
_file_size"
]
=
nil
@instance
[
:"
#{
@name
}
_updated_at"
]
=
nil
instance_write
(
:file_name
,
nil
)
instance_write
(
:content_type
,
nil
)
instance_write
(
:file_size
,
nil
)
instance_write
(
:updated_at
,
nil
)
end
def
flush_errors
#:nodoc:
...
...
test/attachment_test.rb
View file @
ff6e8485
...
...
@@ -232,12 +232,12 @@ class AttachmentTest < Test::Unit::TestCase
context
"with a file assigned in the database"
do
setup
do
@
instance
.
stubs
(
:[]
).
with
(
:avatar_
file_name
).
returns
(
"5k.png"
)
@
instance
.
stubs
(
:[]
).
with
(
:avatar_
content_type
).
returns
(
"image/png"
)
@
instance
.
stubs
(
:[]
).
with
(
:avatar_
file_size
).
returns
(
12345
)
@
attachment
.
stubs
(
:instance_read
).
with
(
:
file_name
).
returns
(
"5k.png"
)
@
attachment
.
stubs
(
:instance_read
).
with
(
:
content_type
).
returns
(
"image/png"
)
@
attachment
.
stubs
(
:instance_read
).
with
(
:
file_size
).
returns
(
12345
)
now
=
Time
.
now
Time
.
stubs
(
:now
).
returns
(
now
)
@
instance
.
stubs
(
:[]
).
with
(
:avatar_
updated_at
).
returns
(
Time
.
now
)
@
attachment
.
stubs
(
:instance_read
).
with
(
:
updated_at
).
returns
(
Time
.
now
)
end
should
"return a correct url even if the file does not exist"
do
...
...
@@ -251,7 +251,7 @@ class AttachmentTest < Test::Unit::TestCase
context
"with the updated_at field removed"
do
setup
do
@
instance
.
stubs
(
:[]
).
with
(
:avatar_
updated_at
).
returns
(
nil
)
@
attachment
.
stubs
(
:instance_read
).
with
(
:
updated_at
).
returns
(
nil
)
end
should
"only return the url without the updated_at when sent #url"
do
...
...
@@ -264,7 +264,7 @@ class AttachmentTest < Test::Unit::TestCase
end
should
"return the proper path when filename has multiple .'s"
do
@
instance
.
stubs
(
:[]
).
with
(
:avatar_
file_name
).
returns
(
"5k.old.png"
)
@
attachment
.
stubs
(
:instance_read
).
with
(
:
file_name
).
returns
(
"5k.old.png"
)
assert_equal
"./test/../tmp/avatars/dummies/original/
#{
@instance
.
id
}
/5k.old.png"
,
@attachment
.
path
end
...
...
@@ -331,10 +331,10 @@ class AttachmentTest < Test::Unit::TestCase
@existing_names
=
@attachment
.
styles
.
keys
.
collect
do
|
style
|
@attachment
.
path
(
style
)
end
@
instance
.
expects
(
:[]=
).
with
(
:avatar_
file_name
,
nil
)
@
instance
.
expects
(
:[]=
).
with
(
:avatar_
content_type
,
nil
)
@
instance
.
expects
(
:[]=
).
with
(
:avatar_
file_size
,
nil
)
@
instance
.
expects
(
:[]=
).
with
(
:avatar_
updated_at
,
nil
)
@
attachment
.
expects
(
:instance_write
).
with
(
:
file_name
,
nil
)
@
attachment
.
expects
(
:instance_write
).
with
(
:
content_type
,
nil
)
@
attachment
.
expects
(
:instance_write
).
with
(
:
file_size
,
nil
)
@
attachment
.
expects
(
:instance_write
).
with
(
:
updated_at
,
nil
)
@attachment
.
assign
nil
@attachment
.
save
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