Commit 2d28dbca by Mike Burns

Move the attachment query to the HasAttachedFile class

parent c555f517
...@@ -192,10 +192,6 @@ module Paperclip ...@@ -192,10 +192,6 @@ module Paperclip
attachment = record.send(name) attachment = record.send(name)
attachment.send(:flush_errors) attachment.send(:flush_errors)
end end
define_method "#{name}?" do
send(name).file?
end
end end
end end
end end
......
...@@ -13,6 +13,7 @@ module Paperclip ...@@ -13,6 +13,7 @@ module Paperclip
def define def define
define_getter define_getter
define_setter define_setter
define_query
end end
private private
...@@ -45,5 +46,13 @@ module Paperclip ...@@ -45,5 +46,13 @@ module Paperclip
send(name).assign(file) send(name).assign(file)
end end
end end
def define_query
name = @name
@klass.send :define_method, "#{@name}?" do
send(name).file?
end
end
end end
end end
...@@ -10,6 +10,10 @@ class HasAttachedFileTest < Test::Unit::TestCase ...@@ -10,6 +10,10 @@ class HasAttachedFileTest < Test::Unit::TestCase
should 'define a getter on the class object' do should 'define a getter on the class object' do
assert_adding_attachment('avatar').defines_method('avatar') assert_adding_attachment('avatar').defines_method('avatar')
end end
should 'define a query on the class object' do
assert_adding_attachment('avatar').defines_method('avatar?')
end
end end
private 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