class Blobsterix::Transformations::TransformationChain
Attributes
logger[R]
target_blob_access[R]
Public Class Methods
new(blob_access, input_data, logger)
click to toggle source
# File lib/blobsterix/transformation/transformation_chain.rb, line 5 def initialize(blob_access, input_data, logger) @blob_access=blob_access @target_blob_access=nil @input_data = input_data @transformations = [] @logger = logger end
Public Instance Methods
add(transfo, value)
click to toggle source
# File lib/blobsterix/transformation/transformation_chain.rb, line 22 def add(transfo, value) return if transfo == nil @transformations << [transfo, value] end
cache()
click to toggle source
# File lib/blobsterix/transformation/transformation_chain.rb, line 13 def cache @cache||=Blobsterix.cache end
do()
click to toggle source
# File lib/blobsterix/transformation/transformation_chain.rb, line 27 def do() with_tempfiles do |keys| last_key = "#{@input_data.path}" begin current_transformation = nil @transformations.each{|trafo| current_transformation = trafo new_key = keys.delete_at(0) trafo[0].transform(last_key, new_key, trafo[1]) last_key = new_key } rescue StandardError => e logger.error "Transformation: #{current_transformation} failed with #{e.message}" break end cache.put(@target_blob_access, last_key) @target_blob_access.reset! end unless @target_blob_access.get.valid @target_blob_access end
finish(accept_type, trafo)
click to toggle source
# File lib/blobsterix/transformation/transformation_chain.rb, line 54 def finish(accept_type, trafo) if @transformations.empty? or (not @transformations.last[0].output_type.equal?(accept_type) and not @transformations.last[0].is_format?) @transformations << [trafo, nil] if trafo != nil && trafo.is_format? end accept_type = @transformations.empty? || !@transformations.last[0].is_format? ? nil : @transformations.last[0].output_type @target_blob_access = Blobsterix::BlobAccess.new(:bucket => @blob_access.bucket, :id => @blob_access.id, :trafo => @transformations.map{|trafo,value| [trafo.name, value]}, :accept_type => accept_type) end
last_type()
click to toggle source
# File lib/blobsterix/transformation/transformation_chain.rb, line 17 def last_type() return Blobsterix::AcceptType.new(@input_data.mimetype) if @transformations.empty? @transformations.last[0].output_type end
Private Instance Methods
with_tempfiles() { |keys| ... }
click to toggle source
# File lib/blobsterix/transformation/transformation_chain.rb, line 64 def with_tempfiles tmpFiles = @transformations.size.times.map{|index| Tempfile.new("blobsterix_#{Thread.current.object_id}_#{index}") } keys = tmpFiles.map{|f| f.path } yield keys tmpFiles.each { |f| f.close f.unlink } end