Changeset 1184

Show
Ignore:
Timestamp:
07/11/08 21:51:27 (6 months ago)
Author:
alban
Message:

Retourne un Cast#size a 0 quand le fichier n'est pas trouve

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/models/cast.rb

    r1121 r1184  
    11class Cast < ActiveRecord::Base 
    22        belongs_to :document 
    3          
     3 
    44        FORMATS = %w(ogg mp3) 
    5          
     5 
    66        def update_file(format = "ogg") 
    77                puts "DEBUG: #{RAILS_ROOT}/bin/encode #{document.path} #{path(format)} #{format}" 
    88                system "#{RAILS_ROOT}/bin/encode", document.path, path(format), format 
    99        end 
    10          
     10 
    1111        def before_destroy 
    1212                FORMATS.each do |format| 
     
    1818          "#{RAILS_ROOT}/media/cast/#{filename(format)}" 
    1919        end 
    20          
     20 
    2121        def filename(format = "ogg") 
    2222          "#{id}.#{format}" 
    2323        end 
    24          
    25         def size(format = "ogg")  
    26                File.size(path(format)) 
     24 
     25        def size(format = "ogg") 
     26          File.exists?(path(format)) ? File.size(path(format)) : 0 
    2727        end 
    28          
     28 
    2929        def uptodate?(format = "ogg") 
    3030                FileUtils.uptodate?(path(format), document.path) 
    3131        end 
    32          
     32 
    3333        def self.update 
    3434                Cast.find(:all).each do |cast| 
     
    4242                        end 
    4343                end 
    44                                  
     44 
    4545                Document.find(:all).delete_if { |d| !d.uploaded? or !d.casts.empty? }.each do |document| 
    4646                        puts "INFO: create cast for document #{document.id}"