Commit 2d28dbca by Mike Burns

Move the attachment query to the HasAttachedFile class

parent c555f517
......@@ -192,10 +192,6 @@ module Paperclip
attachment = record.send(name)
attachment.send(:flush_errors)
end
define_method "#{name}?" do
send(name).file?
end
end
end
end
......
......@@ -13,6 +13,7 @@ module Paperclip
def define
define_getter
define_setter
define_query
end
private
......@@ -45,5 +46,13 @@ module Paperclip
send(name).assign(file)
end
end
def define_query
name = @name
@klass.send :define_method, "#{@name}?" do
send(name).file?
end
end
end
end
......@@ -10,6 +10,10 @@ class HasAttachedFileTest < Test::Unit::TestCase
should 'define a getter on the class object' do
assert_adding_attachment('avatar').defines_method('avatar')
end
should 'define a query on the class object' do
assert_adding_attachment('avatar').defines_method('avatar?')
end
end
private
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment