Commit ad034bae by Jon Yurek

A bit of name refactoring

parent 525b2968
...@@ -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
......
...@@ -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)
......
...@@ -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"
......
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