Sha256: f0496eb0a74bc8f35cb8cc2dcb34a0205fc4c4b5db24179c5b6c7e04f8b5336c

Contents?: true

Size: 1.61 KB

Versions: 26

Compression:

Stored size: 1.61 KB

Contents

class Document < ActiveRecord::Base
  include SocialStream::Models::Object

  IMAGE_FORMATS = ["doc","ppt","xls","rar","zip","mpeg","plain","pdf"]

  has_attached_file :file, 
                    :url => '/:class/:id.:extension',
                    :path => ':rails_root/documents/:class/:id_partition/:style/:filename.:extension'
  
  validates_attachment_presence :file
  validates_presence_of :title
  
  before_validation(:on => :create) do
    set_title_and_description
  end
  
  define_index do
    indexes title
    indexes file_file_name, :as => :file_name
    indexes description
    indexes activity_object.tags.name, :as => :tags
    
    where "type IS NULL"
    
    has created_at
  end
  
  class << self 
    def new(*args)
      if !(self.name == "Document")
        return super
       end 
      doc = super
      
      if(doc.file_content_type.nil?)
        return doc
      end
      
      if !(doc.file_content_type =~ /^image.*/).nil?
        return Picture.new *args
      end
      
      if !(doc.file_content_type =~ /^audio.*/).nil?
        return Audio.new *args
      end
      
      if !(doc.file_content_type =~ /^video.*/).nil?
        return Video.new *args
      end
      
      return doc
    end
  end

  def mime_type
    Mime::Type.lookup(file_content_type)
  end

  def format
    mime_type.to_sym
  end

  # Thumbnail file
  def thumb(size, helper)
    if format && IMAGE_FORMATS.include?(format.to_s)
      "#{ size.to_s }/#{ format }.png"
    else
      "#{ size.to_s }/default.png"
    end
  end
  
  protected
  
  def set_title_and_description
    self.title = self.file_file_name
  end
    
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
social_stream-0.13.2 documents/app/models/document.rb
social_stream-0.13.1 documents/app/models/document.rb
social_stream-0.13.0 documents/app/models/document.rb
social_stream-documents-0.5.0 app/models/document.rb
social_stream-0.12.14 documents/app/models/document.rb
social_stream-documents-0.4.8 app/models/document.rb
social_stream-0.12.13 documents/app/models/document.rb
social_stream-documents-0.4.7 app/models/document.rb
social_stream-0.12.12 documents/app/models/document.rb
social_stream-documents-0.4.6 app/models/document.rb
social_stream-0.12.11 documents/app/models/document.rb
social_stream-0.12.10 documents/app/models/document.rb
social_stream-0.12.9 documents/app/models/document.rb
social_stream-documents-0.4.5 app/models/document.rb
social_stream-0.12.8 documents/app/models/document.rb
social_stream-0.12.7 documents/app/models/document.rb
social_stream-0.12.6 documents/app/models/document.rb
social_stream-0.12.5 documents/app/models/document.rb
social_stream-documents-0.4.4 app/models/document.rb
social_stream-0.12.4 documents/app/models/document.rb