Sha256: ebff3355b2bcb50de3d5cd08717428a573888834a00e9215e5bfb0273002af7d

Contents?: true

Size: 725 Bytes

Versions: 3

Compression:

Stored size: 725 Bytes

Contents

module Sprockets
  class OutputFile
    attr_reader :source_lines
    
    def initialize
      @source_lines = []
      @source_file_mtimes = {}
    end
    
    def record(source_line)
      source_lines << source_line
      record_mtime_for(source_line.source_file)
      source_line
    end
    
    def to_s
      source_lines.join
    end

    def mtime
      @source_file_mtimes.values.max
    end
    
    def save_to(filename)
      timestamp = mtime
      File.open(filename, "w") { |file| file.write(to_s) }
      File.utime(timestamp, timestamp, filename)
      true
    end

    protected
      def record_mtime_for(source_file)
        @source_file_mtimes[source_file] ||= source_file.mtime
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sstephenson-sprockets-0.3.0 lib/sprockets/output_file.rb
sstephenson-sprockets-0.4.0 lib/sprockets/output_file.rb
sstephenson-sprockets-0.5.0 lib/sprockets/output_file.rb