Sha256: 27832277e6fa59824dfcc7801cb117fd5c9cbc423eb2cb041757c6f89f92b8fe

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

module Polygallery
  module ActsAsPolyphoto
    extend ActiveSupport::Concern

    DEFAULTS = {
      :paperclip => {
        :styles => {:medium => '300x300#', :thumb => '100x100#'},
        :default_url => '/images/:style/missing.png'
      }
    }

    included do
      attr_accessor :photo_to_upload,
                    :galleryable_id, :galleryable_type, :gallery_title

      # has_attached_file :photo,
      #                   :styles => PAPERCLIP_SETTINGS[:styles], # ->(a) { if a.instance.class.name then raise a.instance.class.name else PAPERCLIP_SETTINGS[:styles] end },
      #                   :default_url => PAPERCLIP_SETTINGS[:default_url]
      # validates_attachment_content_type :photo, :content_type => /\Aimage\/.*\Z/
      # validates_attachment_presence :photo # TODO: make this a setting
      
      belongs_to :gallery, :class_name => 'Polygallery::Gallery'

      after_initialize :init_attachment
      before_save :process_photo_to_upload
    end

    module ClassMethods
    end

    def paperclip_settings
      return self.gallery.polygallery_settings[:paperclip] if self.gallery.present?
      DEFAULTS[:paperclip]
    end

    def process_photo_to_upload
      self.photo = File.open(photo_to_upload) if photo_to_upload.present?
    end

    def init_attachment
      self.class.has_attached_file :photo,
                        :styles => paperclip_settings[:styles],
                        :default_url => paperclip_settings[:default_url]
      self.class.validates_attachment_content_type :photo, :content_type => /\Aimage\/.*\Z/
      # self.class.validates_attachment_presence :photo # TODO: make this a setting
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
polygallery-0.1.2 app/models/concerns/polygallery/acts_as_polyphoto.rb