C0 code coverage information
Generated on Fri Aug 25 11:26:27 PDT 2006 with rcov 0.7.0
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 require 'RMagick'
2
3 class Image < ActiveRecord::Base
4 has_many :articles
5 belongs_to :image_data
6 #after_save :save_to_disk
7
8 #validates_format_of :content_type, :with => /^image/, :message => "--- you can only upload pictures"
9
10 attr_accessor :image_type
11
12 # overload to do our cool tricks..
13 def self.new_with_data(opts = [])
14 if !opts["image"].nil?
15 rv = ImageData.create :image_data => opts["image"].read
16 opts["original_filename"] = base_part_of(opts["image"].original_filename)
17 opts["content_type"] = opts["image"].content_type.chomp
18 opts["image_data_id"] = rv.id
19
20 opts.delete("image") # no needy
21 self.new(opts)
22 end
23 # need to rescue the error here FIXME
24 end
25
26 def image=(image_field)
27 self.original_filename = base_part_of(image_field.original_filename)
28 self.content_type = image_field.content_type.chomp
29 #File.delete(image_field.path)
30 end
31
32 def set_constraints(constraint_x, constraint_y)
33 article_image = aspect_resize_image!(:image_data, constraint_x, constraint_y)
34 self.original_x = article_image.columns
35 self.original_y = article_image.rows
36 end
37
38 def create_thumb(thumb_type, constraint_x, constraint_y)
39 thumb_image = aspect_resize_image!(thumb_type, constraint_x, constraint_y)
40 case thumb_type
41 when :big_thumb
42 self.thumb_x = thumb_image.columns
43 self.thumb_y = thumb_image.rows
44 when :small_thumb
45 self.small_thumb_x = thumb_image.columns
46 self.small_thumb_y = thumb_image.rows
47 when :tiny_thumb
48 self.tiny_thumb_x = thumb_image.columns
49 self.tiny_thumb_y = thumb_image.rows
50 end
51 end
52
53 def url(tag_type)
54 "/images/#{tag_type}/#{self.id}.#{self.original_filename}"
55 end
56
57 private
58
59 def self.base_part_of(file_name)
60 name = File.basename(file_name)
61 name.gsub(/[^\w._-]/, '')
62 end
63
64 def aspect_resize_image!(image_field, constraint_x, constraint_y)
65 if self.image_data.image_data.length == 0
66 return false
67 end
68
69 article_image = Magick::Image.from_blob(self.image_data.image_data).first
70
71 if article_image.columns > constraint_x
72 article_image.change_geometry("#{constraint_x.to_s}x#{constraint_y ? constraint_y.to_s : ''}") {| cols, rows, img | img.resize!(cols, rows) }
73 end
74
75 self.image_data[image_field] = article_image.to_blob
76 self.image_data.save
77
78 return article_image
79 end
80
81 def save_to_disk
82 job_key = MiddleMan.new_worker(:class => :image_writer_worker, :args => self)
83 end
84 end
Generated using the rcov code coverage analysis tool for Ruby version 0.7.0.