Sha256: 564667777a425e4db5df1c8516a84c18607321080e456fca61ccaf48e0b58439

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

# Prevents you from exporting invalid trackers
class Tracksperanto::Middleware::Lint < Tracksperanto::Middleware::Base
  class NoTrackersExportedError < RuntimeError
    def message
      "There were no trackers exported"
    end
  end
  
  class EmptyTrackerSentError < RuntimeError
    def initialize(name)
      @name  = name
    end
    
    def message
      "The tracker #{@name} contained no keyframes. Probably there were some filtering ops done and no keyframes have been exported"
    end
  end

  class TrackerRestartedError < RuntimeError
    def initialize(name)
      @name  = name
    end
    
    def message
      "The tracker #{@name} has been sent before the last tracker finished"
    end
  end
  
  def start_export(w, h)
    @trackers = 0
    @keyframes = 0
    @last_tracker_name = nil
    super
  end
  
  def start_tracker_segment(name)
    raise TrackerRestartedError.new(name) if @in_tracker
    
    @in_tracker = true
    @last_tracker_name = name
    @keyframes = 0
    super
  end
  
  def export_point(*a)
    @keyframes += 1
    super
  end
  
  def end_tracker_segment
    raise EmptyTrackerSentError.new(@last_tracker_name) if @keyframes.zero?
    @trackers +=1
    @in_tracker = false
    super
  end
  
  def end_export
    raise NoTrackersExportedError if @trackers.zero?
    super
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tracksperanto-2.7.0 lib/middleware/lint.rb
tracksperanto-2.6.3 lib/middleware/lint.rb
tracksperanto-2.6.2 lib/middleware/lint.rb
tracksperanto-2.6.1 lib/middleware/lint.rb
tracksperanto-2.6.0 lib/middleware/lint.rb
tracksperanto-2.5.0 lib/middleware/lint.rb
tracksperanto-2.4.1 lib/middleware/lint.rb
tracksperanto-2.3.3 lib/middleware/lint.rb
tracksperanto-2.3.2 lib/middleware/lint.rb
tracksperanto-2.3.1 lib/middleware/lint.rb