public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
fix failing tests, stop swallowing unnecessary errors in with_image

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2454 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Wed Nov 08 21:31:17 -0800 2006
commit  2f1befcea511fccf66668880e6700dd02dca16a7
tree    fc909c17faa56a25863878efd9eb214a4045e172
parent  022253aad3214bba3c96145b42e95c2a8e88f51c
...
58
59
60
61
 
62
63
64
...
58
59
60
 
61
62
63
64
0
@@ -58,7 +58,7 @@ module Technoweenie # :nodoc:
0
           with_options :foreign_key => 'parent_id' do |m|
0
             m.has_many :thumbnails, :dependent => :destroy, :class_name => options[:thumbnail_class].to_s
0
             m.belongs_to :parent, :class_name => self.base_class.to_s
0
- end if attachment_attributes[:parent_id]
0
+ end #if attachment_attributes[:parent_id]
0
 
0
           include set_fs_path || options[:storage] == :file_system ? FileSystemMethods : DbFileMethods
0
           after_save :create_attachment_thumbnails # allows thumbnails with parent_id to be created
...
16
17
18
19
 
 
 
 
 
 
 
 
20
21
22
23
24
25
26
27
28
...
16
17
18
 
19
20
21
22
23
24
25
26
27
 
 
 
 
 
28
29
30
0
@@ -16,13 +16,15 @@ module Technoweenie # :nodoc:
0
 
0
       # Yields a block containing an RMagick Image for the given binary data.
0
       def with_image(binary_data, &block)
0
- binary_data = Magick::Image::from_blob(binary_data).first unless !Object.const_defined?(:Magick) || binary_data.is_a?(Magick::Image)
0
+ begin
0
+ binary_data = Magick::Image::from_blob(binary_data).first unless !Object.const_defined?(:Magick) || binary_data.is_a?(Magick::Image)
0
+ rescue
0
+ # Log the failure to load the image. This should match ::Magick::ImageMagickError
0
+ # but that would cause acts_as_attachment to require rmagick.
0
+ logger.debug("Exception working with image: #{$!}")
0
+ binary_data = nil
0
+ end
0
         block.call binary_data if block && binary_data
0
- rescue
0
- # Log the failure to load the image. This should match ::Magick::ImageMagickError
0
- # but that would cause acts_as_attachment to require rmagick.
0
- logger.debug("Exception working with image: #{$!}")
0
- binary_data = nil
0
       ensure
0
         !binary_data.nil?
0
       end
...
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
50
51
52
 
 
 
 
 
53
54
55
...
5
6
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
9
10
...
36
37
38
39
40
41
42
43
44
45
46
0
@@ -5,20 +5,6 @@ module Technoweenie # :nodoc:
0
       def self.included(base) #:nodoc:
0
         base.before_update :rename_file
0
         base.after_save :save_to_storage # so the id can be part of the url
0
-
0
- # The attachment ID used in the full path of a file
0
- base.class_eval do
0
- protected
0
- if base.attachment_attributes[:parent_id]
0
- def attachment_path_id
0
- parent_id || id
0
- end
0
- else
0
- def attachment_path_id
0
- id
0
- end
0
- end
0
- end
0
       end
0
 
0
       # Gets the attachment data
0
@@ -50,6 +36,11 @@ module Technoweenie # :nodoc:
0
         @base_path ||= File.join(RAILS_ROOT, 'public')
0
       end
0
 
0
+ # The attachment ID used in the full path of a file
0
+ def attachment_path_id
0
+ ((attachment_attributes[:parent_id] && parent_id) || id).to_s
0
+ end
0
+
0
       # Gets the public path to the file
0
       # The optional thumbnail argument will output the thumbnail's filename.
0
       def public_filename(thumbnail = nil)
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
 
22
23
24
...
77
78
79
80
 
81
82
83
...
157
158
159
160
 
 
 
 
 
 
 
161
162
163
...
1
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
 
6
7
8
9
10
...
63
64
65
 
66
67
68
69
...
143
144
145
 
146
147
148
149
150
151
152
153
154
155
0
@@ -1,24 +1,10 @@
0
 module Technoweenie # :nodoc:
0
   module ActsAsAttachment # :nodoc:
0
     module InstanceMethods
0
- def self.included(base)
0
- base.class_eval do
0
- protected
0
- if base.attachment_attributes[:parent_id]
0
- def find_or_initialize_thumbnail(file_name_suffix)
0
- thumbnail_class.find_or_initialize_by_thumbnail_and_parent_id(file_name_suffix.to_s, id)
0
- end
0
- else
0
- def find_or_initialize_thumbnail(file_name_suffix)
0
- thumbnail_class.find_or_initialize_by_thumbnail(file_name_suffix.to_s)
0
- end
0
- end
0
- end
0
- end
0
-
0
       # Checks whether the attachment's content type is an image content type
0
       def image?
0
- self.class.image?(content_type.to_s.strip)
0
+ class << self; def image?() @is_image; end; end
0
+ @is_image = self.class.image?(content_type.to_s.strip)
0
       end
0
       
0
       def thumbnailable?
0
@@ -77,7 +63,7 @@ module Technoweenie # :nodoc:
0
           return nil
0
         end
0
         with_image data do |img|
0
- resized_img = (attachment_options[:resize_to] && (!attachment_attributes(:parent_id) || parent_id.nil?)) ?
0
+ resized_img = (attachment_options[:resize_to] && (!attachment_attributes[:parent_id] || parent_id.nil?)) ?
0
             thumbnail_for_image(img, attachment_options[:resize_to]) : img
0
           data = resized_img.to_blob
0
           self.width = resized_img.columns if respond_to?(:width)
0
@@ -157,7 +143,13 @@ module Technoweenie # :nodoc:
0
             errors.add attr_name, ActiveRecord::Errors.default_error_messages[:inclusion] unless enum.nil? || enum.include?(send(attr_name))
0
           end
0
         end
0
-
0
+
0
+ def find_or_initialize_thumbnail(file_name_suffix)
0
+ attachment_attributes[:parent_id] ?
0
+ thumbnail_class.find_or_initialize_by_thumbnail_and_parent_id(file_name_suffix.to_s, id) :
0
+ thumbnail_class.find_or_initialize_by_thumbnail(file_name_suffix.to_s)
0
+ end
0
+
0
         # Yanked from ActiveRecord::Callbacks, modified so I can pass args to the callbacks besides self.
0
         # Only accept blocks, however
0
         def callback_with_args(method, arg = self)

Comments

    No one has commented yet.