public
Description: Treat an ActiveRecord model as a file attachment, storing its patch, size, content type, etc.
Homepage: http://weblog.techno-weenie.net
Clone URL: git://github.com/technoweenie/attachment_fu.git
Click here to lend your support to: attachment_fu and make a donation at www.pledgie.com !
attachment_fu / lib / attachment_fu / pixels.rb
100644 30 lines (27 sloc) 0.728 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module AttachmentFu
  module Pixels
    def self.[](key)
      @@key_to_class ||= {}
      @@key_to_class[key] ||= begin
        path = key.to_s
        require "attachment_fu/pixels/#{path}"
        const_get(path.classify)
      end
    end
 
    # Base class for all Pixel-related tasks
    class Task
      def initialize(klass, options)
        options[:with] ||= :mojo_magick
        extend AttachmentFu::Pixels[options[:with]]
      end
    end
 
    class Image
      attr_accessor :filename, :width, :height, :size
 
      def initialize(filename = nil)
        @filename = filename
        yield self if block_given?
        @size = File.size(filename) if filename && File.exist?(filename)
      end
    end
  end
end