Method: S3FileCollection#add

Defined in:
lib/cosmos/utilities/s3_file_cache.rb

#add(s3_path, size, priority) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/cosmos/utilities/s3_file_cache.rb', line 93

def add(s3_path, size, priority)
  @mutex.synchronize do
    @array.each do |file|
      if file.s3_path == s3_path
        file.priority = priority if priority < file.priority
        @array.sort! {|a,b| a.priority <=> b.priority}
        return file
      end
    end
    file = S3File.new(s3_path, size, priority)
    @array << file
    @array.sort! {|a,b| a.priority <=> b.priority}
    return file
  end
end